動手動腦10.21
阿新 • • 發佈:2020-10-22
1.
class Grandparent { public Grandparent() { System.out.println("GrandParent Created."); } public Grandparent(String string) { System.out.println("GrandParent Created.String:" + string); } } class Parent extends Grandparent {public Parent() { //super("Hello.Grandparent."); System.out.println("Parent Created"); // super("Hello.Grandparent."); } } class Child extends Parent { public Child() { System.out.println("Child Created"); } } publicclass TestInherits { public static void main(String args[]) { Child c = new Child(); } }
執行截圖:
2.
執行截圖:
實際呼叫的是Object類的public void println(Objext x)
這一方法呼叫了String類的valueOf方法
valueOf方法內部又呼叫Object.toString方法
public StringtoString(){
return get Class().getName()+"@"+Integer.toHexString(bashCode);
}
hashCode方法是本地方法,由JVM設計者實現
public native int hashCode();