动手动脑10.21

时间:2020-10-21
本文章向大家介绍动手动脑10.21,主要包括动手动脑10.21使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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");

      }

}



public class TestInherits 
{


    public static void main(String args[])
     {

            Child c = new Child();
    
  }

}

运行截图:

2.

 运行截图:

 实际调用的是Object类的public void println(Objext x)

这一方法调用了String类的valueOf方法

valueOf方法内部又调用Object.toString方法

public String toString(){

return get Class().getName()+"@"+Integer.toHexString(bashCode);

}

 hashCode方法是本地方法,由JVM设计者实现

public native int hashCode();

原文地址:https://www.cnblogs.com/feng747/p/13855199.html