aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance" Watch "Inheritance" New topic
Author

Inheritance

Chitra Jay
Ranch Hand

Joined: May 02, 2002
Posts: 76
From Khalid Mughal:
All the members of the superclass are inherited by the subclass
The answer given: true
Well,JLS says that
Constructors ,static initializers and instance initializers are not members of the class and therefore not inherited..
But what happened to private members of the superclass?? I thought that they are not inherited but visible in the subclass object.
Please Clarify
Chitra
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
private members are neither inherited nor visible in the subclass.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
From Mughal as well "Private members are not accessible from any other class. This also applies to subclasses, whether they are in the same package or not. It is not to be confused with inheritance of members by the subclass. ~*~ Members are still inherited, but they are not accessible in the subclass. ~*~"
So they are inherited but not accessible, what's the signeficance of that? I'm not sure, maybe it affects if a member in the subclass tries to hide the member in the super class.
Can anyone tell?


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Alferd you made a very good point. To further your argument:
Let us say that a member method is inherited by sub-class because it is not private and not static. Just it happens that within this method, it access some of the private members of super class. Now you are executing this method in the sub-class as an inherited method. Technically, sub-class does not have direct access to super class private members. But via this method can access them from super class even though it is run on sub class objects.
Hope this makes sense...
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Barkat,
that's exactly how private members are supposed to be accessed.
For more info about private members, please check out:
JLS 6.6.8 Example: private Fields, Methods, and Constructors
JLS 8.2.1.3 Inheritance with private
JLS 8.2 Class Members
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance