object - Java error @d622e5 -
this question has reply here:
how utilize tostring method in java? 13 answersclass tank{ int level; } class aliasing{ public static void main(string args[]){ tank t1 = new tank(); tank t2 = new tank(); t1.level=21; t2.level=32; system.out.println("t1: " + t1 + " t2: " + t2); } }
this block of code produces output: t1: tank@1b4b24d t2: tank@260829. wrong, don't know why of sudden code producing nosense. also, if intiliaze primitive value can print out no problem right value, don't know why objects messing up.
you need override tostring() method in tank class produce meaningful representation of object.
java object
No comments:
Post a Comment