String name = "A";
public void a(){
System.out.println("i am " + name);
}
public void getName(){
System.out.println(name);
}
}
//=====================================
public class B extends A {
String name = "B";
public void b(){
System.out.println("i am " + name);
}
public void getName(){
System.out.println("extend " + name);
}
}
//=====================================
public static void main(String[] args) {
A a = new B();
a.a(); // i am A
a.getName(); // extend B
//----------------------------
B b = (B)a;
b.a(); // 容易出問題 => i am A
b.getName(); // extend B
b.b(); // i am B
}