aspose file tools*
The moose likes Beginning Java and the fly likes overriding toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overriding toString()" Watch "overriding toString()" New topic
Author

overriding toString()

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
code:
class arr1
{
public static void main(String a[])
{
int[] b = ( 1, 2, 3};
System.out.println("string " + b);
/* According to JLS, string concat. operator + and a reference (in this case array b) will convert the reference to a String by invoking toString method of the referenced object. */
}
}
Now I want to override toString() of Object.
I do not know where to include this code:
public String toString()
{
return "array string" ;
}
So when I run above code , instead of generating
string : some junk
i need
string : array string // overrides
Jane Rozen
Ranch Hand

Joined: Feb 12, 2000
Posts: 53

is this what you want to achieve?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding toString()
 
Similar Threads
Question #2 from Doug's book
Default values problem.
Printing two substrings
Object Comparison
toString method