Ok so I have studied java all semester and thought I had a clear understanding about inheritance and super/sub classes. Today we were given as assignment for making a superclass
When you inheritance other class, you cannot access your private attributes directly. So, if you have a class named "A" and other called "B", and make B extends A, B cannot access private attributes of A.
Think this like a protection. This way, you can write some attributes in class "A" that you dont want others classes access it through inheritance.
The "B" class can access only public, protected and default attributes directly in "A" class. But if you want to access a private attribute in "A" class for any reasons, you can write a method in "A" to return this attribute.
public class A{
private int foo;
public int getFoo(){
return this.foo;
}
}
public class B extends A{
public void doSomething(){
getFoo(); //return the private foo attribute of superclass
}
}