this doubt don't let me sleep, help me to understand
i got this Class
--------------------------------------------------------
public class MyPoint {
public int x;
public int y;
public String toString() {
return ("[" + x + "," + y + "]");
}
}
---------------------------------------------------------
then i use this other Class to test the first one
---------------------------------------------------------
public class TestMyPoint {
public static void main(String[] args){
MyPoint start = new MyPoint();
MyPoint end = new MyPoint();
start.x=10;
start.y=10;
end.x=20;
end.y=30;
System.out.println("Start point is: " + start);
System.out.println("End point is: " + end);
}
}
-------------------------------------------------------------
and the ouput is:
Start point is: [10,10]
End point is: [20,30]
WHY? if i didn't call the toString Method in any line
then i change the name of the method toString to the name angelo (lol)
as follow
public class MyPoint {
public int x;
public int y;
public String angelo() {
return ("[" + x + "," + y + "]");
}
}
and the ouput was :
Start point is: mypo...@19821f
End point is: mypo...@addbf1
please help me to understand this topic!
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---