As per the link, definition says, The private modifier specifies that the member can only be accessed in its own class.
But the below code is able to access private member item
of super class in sub class.
class SuperType {
private int item;
public void setItem(int item){
this.item = item;
}
public int getItem(){
return item;
}
}
public class SubType extends SuperType{
public static void main(String[] args){
SubType s = new SubType();
s.setItem(2);
System.out.println(s.getItem());
}
}
It is also understood that s.item
does not work, because item
is not a member of SubType
class.
How do i understand this definition?