I just learnt about the toString()
method in object class and how to override it in other class.
class Box {
public String toString(){
return "class Box";
}
}
class B {
public static void main(String args[]){
Box b1=new Box();
System.out.println(b1); //case 1
Box b2=b1; //case 2
}
}
So my question is how does box object know to return the String in the toString()
in class Box in case 1 and return the b1
object's address in case 2?