How do I print the variable name holding my object?
For example, I have:
myclass ob=new myclass()
How would I print \"ob\"?
System.out.println();
Is the command used to print out to the console.
So if you have your own class that you created and instantiated, you could do:
MyObject obj = new MyObject();
System.out.println(obj);
and that would print out the toString()
implementation of MyObject
. The default implementation is not very interesting, so for useful info, you would have to override toString()
.