This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes why String vlass reference variable holds content ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why String vlass reference variable holds content ?" Watch "why String vlass reference variable holds content ?" New topic
Author

why String vlass reference variable holds content ?

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689


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?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
by overriding toString method why it displays string value when reference is displayed?

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Look up PrintWriter.println(Object) in the API to see why.

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


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

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

Joined: Dec 22, 2004
Posts: 26


One good example of runtime polymorphism


bharath
Bharath Chinnadurai Maharajan
Greenhorn

Joined: Dec 22, 2004
Posts: 26

is out a PrintWriter object or a PrintStream object ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41635
    
  55
is out a PrintWriter object or a PrintStream object ?

That's easy enough to find out in the javadocs, isn't it?


Ping & DNS - my free Android networking tools app
 
 
subject: why String vlass reference variable holds content ?