File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reference Variables and Inheritance

 
Thomas Schultz
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Thanks.
 
Santiago Bravo
Ranch Hand
Posts: 226
 
Treimin Clark
Ranch Hand
Posts: 757
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link!

It is from the Exam Lab.
 
Ivan Vrtacnik
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rememmber this:

fields and static members go with the type and not the instance.
instance members go with the instance
 
victor kamat
Ranch Hand
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is what I am saying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic