Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding data hiding and function overriding  RSS feed

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • 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
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!