, . ints.
Person int Student :
super.ID;
Be careful, dynamic dispatch is not performed for member fields. If you define a method for Person that uses a field ID, it will refer to the field Person, not Studentone, even if called in the object Student.
public class A
{
public int ID = 42;
public void inheritedMethod()
{
System.out.println(ID);
}
}
public class B extends A
{
public int ID;
public static void main(String[] args)
{
B b = new B();
b.ID = 1;
b.inheritedMethod();
}
}
The above will print 42, not 1.
source
share