zoukankan      html  css  js  c++  java
  • Java理论学时第六节。课后作业。

    package Fuction;

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

        }

    }

    无super,不调用父类构造方法时。

    在子类构造方法第一个语句时。

    在后面语句时。

    结论。

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

  • 相关阅读:
    剑指offer【面试题10 :矩形覆盖】
    剑指offer【面试题3 :二维数组中的查找】
    GStreamer Tutorials
    CMake Tutorial
    python
    python
    python-线程、进程、协程
    python-类的继承
    python-操作缓存
    python-线程池
  • 原文地址:https://www.cnblogs.com/shenshenxin/p/4946897.html
Copyright © 2011-2022 走看看