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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reference Variables and Inheritance" Watch "Reference Variables and Inheritance" New topic
Author

Reference Variables and Inheritance

Thomas Schultz
Greenhorn

Joined: Nov 07, 2008
Posts: 4


This prints 1 Sub2. Why doesn't it print 2 Sub 2?

Thanks.
Santiago Bravo
Ranch Hand

Joined: Jul 25, 2008
Posts: 226
Thomas,


I posted this question earlier:

http://www.coderanch.com/t/417875/java-programmer-SCJP/certification/System-out-println-non-void


Santiago
My Path to SCJP Certification My Path to SCWCD Certification
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Hi Thomas,

We have a rule here. You must Quote Your Sources. Therefore, please let us know where did you get this question from.

Thanks.
Thomas Schultz
Greenhorn

Joined: Nov 07, 2008
Posts: 4
Thanks for the link!

It is from the Exam Lab.
Ivan Vrtacnik
Greenhorn

Joined: Sep 02, 2008
Posts: 26
If I understand correctly, a is a Test reference to an Arabik object. And the question is why does a.i call the i field of Test and a.getI() calls the getI() of Arabik?
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Rememmber this:

fields and static members go with the type and not the instance.
instance members go with the instance
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Sorry I got that somewhat wrong.
Here is the correct answer:

Fields and static members go with the type,
instance methods go with the class
Ivan Vrtacnik
Greenhorn

Joined: Sep 02, 2008
Posts: 26
So static members and fields are called from the reference, and methods from the object, is that what you're saying?
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Yes that is what I am saying.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reference Variables and Inheritance
 
Similar Threads
examlab mockup 1 question
Question about System.out.print behavior
what is this??? I m confused
strange behavior of overridden call
Question from Exam lab practice Exam 1 about polymorphism