| Author |
ToString method
|
sumaraghavi ragha
Ranch Hand
Joined: Nov 17, 2006
Posts: 118
|
|
HI All Can any one please tell me what is the use of a toString menthod With an example Thanks
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
When you try to access the value of an Object (reference variable) like this System.out.println(obj); OR String s = "Hello"+obj; Then the compiler calls the toString() method on that object. So after compilation you code would look like- System.out.println(obj.toString()); OR String s = "hello"+obj.toString(); As a developer your job is to provide a toString method with your class and return the relevant details about the object as a String from the toString method. Eg.
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
 |
|
|
subject: ToString method
|
|
|