This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding data hiding and function overriding
 
Similar Threads
Doubt about diagram class (realization)
WA #1.....word association
can non-static inner class access any member
andrew has wii
Doubt about diagram class