| Author |
how is toString method used in this question
|
Sneha Kapoor
Ranch Hand
Joined: Jun 08, 2009
Posts: 49
|
|
how is toString method used in this question
Source K&B book.Page 553
|
 |
kaushik vira
Ranch Hand
Joined: Feb 01, 2007
Posts: 102
|
|
Hello Sneha,
As toString method is method of object class... it`s always used to format the output of object.. when you say
System.out.println(obj);
obj.toString() method get called.. and the result of the method will be printed in out stream..
|
kaushik Vira
-------------------------------------
SCJP, Preparing SCWCD..
|
 |
Prasad Kumbhare
Greenhorn
Joined: Oct 18, 2007
Posts: 26
|
|
In this code example, toString() method has been overridden. So instead of printing object's name (it doesn't print object's name by the way), it will print custom message. In this example ,
DVDInfo d = new DVDInfo("Java","Ranch","Group");
System.out.print(d);
Output of this would be "Java Ranch Group"
Hope this helps.
Thanks.
|
Thanks,
Prasad Kumbhare
SCJP 5.0, SCWCD 5.0, SCBCD 5.0
|
 |
 |
|
|
subject: how is toString method used in this question
|
|
|