zoukankan      html  css  js  c++  java
  • 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.

     

    public class ExplorationJDKSource {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            System.out.println(new A());
        }
    
    }
    
    class A{}
    

      

    在编译源代码时,当遇到没有父类的类时,编译器会将其指定一个默认的父类(一般为Object),因此,main方法实际上内部调用了String类的valueOf方法。 valueOf方法内部又调用Object.toString方法: 

    public String toString() { return getClass().getName() +"@" + Integer.toHexString(hashCode()); }
  • 相关阅读:
    js 数组去重的几种方式及原理
    js replace
    gulp的使用方法
    gulp 安装部署
    gulp 的5个方法
    fiddler 监听手机的http请求
    vsCood
    browser-sync使用方法
    browser-sync 安装
    npm 移除第三方包
  • 原文地址:https://www.cnblogs.com/mjhjl/p/14144463.html
Copyright © 2011-2022 走看看