在下面的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 ;
任何幫助表示讚賞。
在此先感謝。