class Father {
int age = 50;
static int score = 75;
public void show() {
System.out.println("這是老爸的show");
}
}
class Son extends Father {
int age = 25;
static int score = 100;
public void show() {
System.out.println("這是兒子的show");
}
}
class Demo1 {
public static void main(String[] args) {
Father f = new Son();
System.out.println(f.age);
f.show();
}
public void age() {
System.out.println(f.age);
}
}
最后幾行代碼報錯,我在main方法里開辟一個方法去找對象,報錯,什么原因?
那是因為它和對象本來就沒有關(guān)系。