myOverLoad buildRect(Point topleft, int w, int h){
x1=topleft.x;
y1=topleft.y;
x2=(x1+w);
y2=(y1+h);
return this;
}
}
class Overload1{
public static void main (String[]args){
my.buildRect(1, 2, 3, 4);
my.buildRect(new Point(1,2), new Point(3,4));
my.buildRect(new Point(1,2),10,11);
System.out.println(my.buildRect(1, 2, 3, 4));
System.out.println(my.buildRect(new Point(5,6), new Point(7,8) ));
System.out.println(my.buildRect(new Point(5,6), new Poin(7,8) ));
}
}
04-18-2005, 05:30 PM
sjalle
I cannot imagine that this will compile as you are using an undeclared and uninitiated
variable (my) in the main method. If you instatiate a new instance of myOverLoad
like:
myOverLoad my=new myOverLoad();
and the call the buildRect method repeatedly you are changing the contents of the
my instance each time. What you should do was make a toString method for the
myOverLoad class like