• 类的继承


    1.子类覆盖父类的成员变量

    class A{
        String name = "tom";
        A(String name){
            this.name = name;
        }
    }
    
    class B extends A{
        String name = "jack";
        B(String name){
            super(name);
        }
    }
    
    public class BigInt {
        public static void main(String[] args) {
            B b = new B("helen");
            System.out.println(b.name);
        }
    }

    运行结果:

    jack

    ---------------------------------------------------------------------------------------------------------------------------------------

    class A{
        String name = "tom";
        A(String name){
            this.name = name;
        }
    }
    
    class B extends A{
        String name = "jack";
        B(String name){
            super(name);
        }
    }
    
    public class BigInt {
        public static void main(String[] args) {
            A b = new B("helen");
            System.out.println(b.name);
        }
    }

    运行结果:

    helen

    ---------------------------------------------------------------------------------------------------------------------------------------

    class A{
        String name = "tom";
        A(String name){
            this.name = name;
        }
    }
    
    class B extends A{
        String name = "jack";
        B(String name){
            super(name);
            this.name = name;
        }
    }
    
    public class BigInt {
        public static void main(String[] args) {
            A b = new B("helen");
            System.out.println(b.name);
        }
    }

    运行结果:

    helen

    ---------------------------------------------------------------------------------------------------------------------------------------

    class A{
        String name = "tom";
        A(String name){
            this.name = name;
        }
    }
    
    class B extends A{
        String name = "jack";
        B(String name){
            super(name);
            this.name = name;
        }
    }
    
    public class BigInt {
        public static void main(String[] args) {
            B b = new B("helen");
            System.out.println(b.name);
        }
    }

    运行结果:

    helen
  • 相关阅读:
    python-单链表的实现
    python-树形结构和遍历
    python四种简单排序
    python数据类型
    python安装和配置
    Js 中的false,零值,null,undefined和空字符串对象
    console和chrom-tool
    js中声明Number的五种方式
    vue下拉搜索
    canvas猜数游戏
  • 原文地址:https://www.cnblogs.com/sunzhongyu008/p/11329134.html
Copyright © 2020-2023  润新知