This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overriding toString()" Watch "overriding toString()" New topic

overriding toString()

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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:
subject: overriding toString()
It's not a secret anymore!