aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes plz explain the o/p Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "plz explain the o/p" Watch "plz explain the o/p" New topic
Author

plz explain the o/p

Mandar Jadhav
Greenhorn

Joined: Oct 01, 2007
Posts: 12

The output of the above program is

value of name in parent object Base class
value of name in child object Base class

Can anyone please explain, how the child object 'getName()' method returns parent object 'name' variable value.
gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80
Both sub class and base class are refering to getName() method of the base class, getName() method has access to String variable name in base class only. getName() method can not see the members of its subclasses. So when we call this method by using base class reference variable or subclass reference variable it will always print the String name of the base class.

I hope I am able to clarify your doubt. Reply!


SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
that was interesting fact!!!


SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80
Dear Sandeep,
If I am wrong somewhere please rectify me. I will love to learn more.
agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70
You are right dude...


Manoj Kumar
Mandar Jadhav
Greenhorn

Joined: Oct 01, 2007
Posts: 12
I got the point....

Thanks gurneeraj .
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Mandar Jadhav,
Welcome to JavaRanch!

In an effort to help everyone get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
UseRealWords

Abbreviations such as "u" or "ur" in
place of "you" and "you are" or "you're" confound language translation software making
it hard for our non-English speaking members to read your posts.
"plz" is not a word in the English language.

Again, welcome to JavaRanch and good luck with your question.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
that was interesting fact!!!
Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
Originally posted by gurneeraj singh:
Both sub class and base class are refering to getName() method of the base class, getName() method has access to String variable name in base class only. getName() method can not see the members of its subclasses. So when we call this method by using base class reference variable or subclass reference variable it will always print the String name of the base class.

I hope I am able to clarify your doubt. Reply!


Please explain this



I get the output as


Value of name in parent object null
Value of name in child object null


Why is that ?
Sun Craven
Greenhorn

Joined: Mar 13, 2008
Posts: 27
hi Sridhar
please note the following :
public void Base()
is not a constructor,and the subclass is same to this.
The public void Base () method and the public void Sub were not benn invoked.Hence,the name variables are null.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: plz explain the o/p