aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how is toString method used in this question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how is toString method used in this question " Watch "how is toString method used in this question " New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how is toString method used in this question