java遗珠之隐藏和覆盖

栏目: Java · 发布时间: 7年前

内容简介:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lastsweetop/article/details/82857467

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lastsweetop/article/details/82857467

1.只有实例方法有覆盖,类方法,类变量和实例变量都是隐藏。

2.覆盖的意思就是会调用具体的子类,而隐藏就看谁去调用。

3.类变量可以隐藏实例变量,实例变量也可也隐藏类变量。

4.类方法和实例方法无法相互覆盖和隐藏。

例子如下:

class Father {
    int a = 1;

    static void b() {
        System.out.println("father b");
    }

}

public class Son extends Father {
    static int a = 2;

    static void b() {
        System.out.println("son b");
    }



    public static void main(String[] args) {
        Father f = new Son();
        System.out.println(f.a);
        f.b();

        Son s=new Son();
        System.out.println(s.a);
        s.b();
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Probabilistic Method Second Edition

The Probabilistic Method Second Edition

Noga Alon、Joel H. Spencer / Wiley-Blackwell / 2000 / $121.95

The leading reference on probabilistic methods in combinatorics-now expanded and updated When it was first published in 1991, The Probabilistic Method became instantly the standard reference on one......一起来看看 《The Probabilistic Method Second Edition》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具