Hi!
I need to override toString() method to print the name of the object. I am assigning the "this" variable in a method to a string object(str = this.toString() and printing the name of the object using System.out.prinln(str) but doing that also prints some hex code and @ sing, I asked this question before somewhere else but the replies weren't very understnadable.
Please help
Thanks!
Comments
: I need to override toString() method to print the name of the object. I am assigning the "this" variable in a method to a string object(str = this.toString() and printing the name of the object using System.out.prinln(str) but doing that also prints some hex code and @ sing, I asked this question before somewhere else but the replies weren't very understnadable.
: Please help
: Thanks!
:
You can override that like any other overriden method:
[code]
class HelloWorld {
public String toString() {
return 'Hello World!';
}
}
[/code]
I've found something that may be useful in looking for 'Introsector' on the sun website.
Good luck!
inside your class you could use something like
[code] public String toString() {
return this.getClass().getName();
}[/code]
which will return the name of the class.