这段代码很长,想起大神看看,能否给各行个注释
class point {int x,y;
String name="a point";
point(){
x=0;
y=0;
}
point (int x,int y,String name){
this.x=x;
this.y=y;
this.name=name;
}
int getX(){
return x;
}
int getY(){
return y;
}
void move(int newX,int newY){
x=newX;
y=newY;
}
point newpoint(String name){
point newp=new point(-x,-y,name);
return newp;
}
boolean equal(int x,int y){
if (this.x==x&&this.y==y)
return true;
else
return false;
}
void print(){
System.out.println(name+":x="+ x +"y="+y);
}
public class UsingOBject{
}
public static void main(String args[]){
point p=new point();
p.print();
p.move(50,50);
System.out.println("**after moving**");
System.out.println("Get x and y directly");
System.out.println("x="+p.x + "y="+p.y);
System.out.println("or Get x and y by calling method");
System.out.println("x="+p.getY()+"y="+p.getY());
if (p.equal(50,50))
System.out.println("I like this point!!!");
else
System.out.println("I hate it !!!");
p.newpoint("a new point ").print();
new point (10,15,"another new point").print();
}
}
我能理解大部分,但有一些我不清楚是如何调用的...