次のJavaコードでは
public class Person {
int age = 18;
}
class Student extends Person {
public Student() {
this.age = 22;
}
public static void main(String[] args) {
Student student = new Student();
student.doSomthing();
}
void doSomthing() {
System.out.println(this.age);
System.out.println(super.age);// Here is something weird, at least for me till rightNow()
}
}
super.ageの値が22で、サブクラスの年齢の値と同じである理由は、18であるはずではありません。
どんな助けでも大歓迎です。
前もって感謝します。