Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why String vlass reference variable holds content ?  RSS feed

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by overriding toString method why it displays string value when reference is displayed?

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up PrintWriter.println(Object) in the API to see why.

This method is being called, because System.out is a PrintWriter.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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.
 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


One good example of runtime polymorphism
 
Bharath Chinnadurai Maharajan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is out a PrintWriter object or a PrintStream object ?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is out a PrintWriter object or a PrintStream object ?

That's easy enough to find out in the javadocs, isn't it?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!