This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding data hiding and function overriding

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java,if we do
BaseClass b = new DerivedClass();
b.field // of base class
b.method //of derived class

But i am not clear why the implementation is different in case of access of field and method.What is the reason??
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fields (member variables) are not polymorphic - they are not looked up dynamically just like methods. You cannot override member variables.

Note that it is usually not a good idea (and it's almost never necessary) to have a member variable in a subclass that has the same name as a member variable in a superclass.
[ February 09, 2007: Message edited by: Jesper Young ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic