aspose file tools*
The moose likes Java in General and the fly likes regarding data hiding and function overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "regarding data hiding and function overriding" Watch "regarding data hiding and function overriding" New topic
Author

regarding data hiding and function overriding

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
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

Joined: Aug 16, 2005
Posts: 14276
    
  21

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: regarding data hiding and function overriding