zoukankan      html  css  js  c++  java
  • 课后总结

    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 {
    
    }

    输出结果:

    探索步骤:

    自我抑郁又自我救赎
  • 相关阅读:
    STL容器内数据删除
    grep 同时满足多个关键字和满足任意关键字
    程序运行栈空间不足程序崩溃问题
    VS2010中设置程序以管理员身份运行
    python 包详解
    select 详解
    Hdu 1166
    CF1204C
    CF1204B
    CF1204A
  • 原文地址:https://www.cnblogs.com/zjm15511858030/p/9890525.html
Copyright © 2011-2022 走看看