• 课后总结


    package TestInherits;
    //继承问题及super的用法
    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(); } }

    1.未取消注释时的结果:

    2.将第一个注释取消时的输出结果:

    3.将第二个注释取消,程序会报错:

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

    子类的构造方法在运行之前,必须调用父类的构造方法

    原因:构造函数的主要作用是初始化。

    不可变类:final

     final即最完美的,最终的,不可更改。

    奇怪的输出:

    package text;
    
    public class text {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            System.out.println(new A());
        }
    
    }
    package text;
    
    public class A {
    
    }

    输出结果:

    探索步骤:

    自我抑郁又自我救赎
  • 相关阅读:
    C++线程池实现-代码分析
    TortoiseGit如何更换用户名和密码
    go 访问apollo配置
    go 操作redis遇到的坑
    java类加载过程
    了解Python
    Java线程
    百度搜索引擎和谷歌搜索引擎的区别
    设置swiper容器同时显示的slide数量
    CSS last-child不起作用
  • 原文地址:https://www.cnblogs.com/zjm15511858030/p/9890525.html
Copyright © 2020-2023  润新知