I'm new to java. Recently I saw some code which was similiar to this:
class A {
protected int myInt;
public static void main(String[] args) {
B b = new B();
b.myFunction();
}
}
class B extends A {
public void myFunction() {
this.myInt = 10;
}
}
As far as I know, when creating a subclass instance, an instance of its parent is created as well. All protected and public members of base class are accessible from the subclass.
If I override myInt
there will be a difference between this.myInt
to super.myInt
because each class will have its own myInt
(B will have access to both).
So, my question is: if I don't override myInt
, which form is preferable, this.myInt
or super.myInt
?