例題如下:
class A {
public static void doSth(){
System.out.println("Doing something in A");
}
}
class B extends A {
public static void doSth(){
System.out.println("Doing something in B");
}
}
class C extends B {
public static void doSth(){
System.out.println("Doing something in C");
}
}
class test {
public static void main(String [] args) {
A.doSth();
B.doSth();
C.doSth();
A aInstance = new B();
B bInstance = new C();
C cInstance = new C();
aInstance.doSth();
bInstance.doSth();
cInstance.doSth();
}
}
執行結果是
Doing something in A
Doing something in B
Doing something in C
Doing something in A
Doing something in B
Doing something in C
前三個我可以理解,後三個我就不懂了,static在這裡是起什麼樣的作用呢?
跪求高手解惑,感謝...