>> Probably because it would compromise encapsulation
yes it's right, private members - is the part of class implementation, both variables and methods. If it can be inhereted, then subclass can see details of implementation - this is violation of main OO principle.
>> You can override such a member but it is not used if called from >>a member of the base class.here is no warning/error issued from >> the compiler!
it's not overriding - it's just define new member of subclass.
Let's imaging you have:
private int id; in your base class, and you override it by:
private String id; in your subclass
so, if try in base class use the overriding member (String instead of int), i think, it will cause troubles :)
Main Topics
Browse All Topics





by: CEHJPosted on 2003-10-11 at 10:57:35ID: 9533386
>>Why are private members treated differently from public and protected members
Probably because it would compromise encapsulation - if they were inherited, they would be accessible and therefore not completely encapsulated
>>You can override such a member but it is not used if called from a member of the base class
This behaviour is expected, since the member would merely be a replacement, much in the same way a constructor would be.