zoukankan      html  css  js  c++  java
  • 第八周课堂作业

    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 TestInherists
    {    
    public static void main(String args[])   
      {         Child c=new Child();   
      }
    }
    复制代码

    其结果为:

    若把上面绿色注释取消,如下

    复制代码
    class Parent extends Grandparent
    {
        public Parent()
        {
            
            System.out.println("Parent Created");
            super("Hello.Grandparent.");
        }
    }
    复制代码

    程序报错

    原因:通过super调用基类构造方法,必须是子类构造方法中的第一个语句

    this 和 super有区别,this用于此类,而super用于父类,若没写super,系统将默认进行super,若写了,则必须放在第一个语句

  • 相关阅读:
    jq的stop
    mouseover,mouseout与mouseenter,mouseleave
    jq的load
    KeyUp 和KeyDown 、KeyPress之间的区别
    jq的error
    $(function() {....}) ,(function($){...})(jQuery)
    delegate事件委托
    将项目提交到git
    linux下安装jenkins
    手写简单的linkedlist
  • 原文地址:https://www.cnblogs.com/ygl888/p/4951068.html
Copyright © 2011-2022 走看看