Forums Register Login
why String vlass reference variable holds content ?

why s displays JAVA is displyed ?

but here x is not displaying JAVA
what to do for displaying JAVA here should i need to change the state of this object?
by overriding toString method why it displays string value when reference is displayed?

Look up PrintWriter.println(Object) in the API to see why.

This method is being called, because System.out is a PrintWriter.

Println() method converts all its parameters to String to print it on console. If it finds the object, then it will call the toString() method on that object.

One good example of runtime polymorphism

is out a PrintWriter object or a PrintStream object ?

is out a PrintWriter object or a PrintStream object ?

That's easy enough to find out in the javadocs, isn't it?
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 870 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 17, 2018 22:18:23.