Java使用super操作被隐藏的成员变量和方法

源代码:

public class Test {
public static void main(String[] args) {
B b=new B();

b.m=3;
b.n=7;

long resultOne=b.g();
long resultTwo=b.f();
long resultThree=b.g();

System.out.println(resultOne);
System.out.println(resultTwo);
System.out.println(resultThree);
}


}


class A{
int m=0;
int n=0;

long f(){
return m+n;
}
}


class B extends A{
int m=1;
int n=1;

long f(){
long result=0;

super.m=10;
super.n=20;

result=super.f()+(m+n);

return result;
}

long g(){
long result=0;
result=super.f();

return result/2;
}
}


程序运行结果:


---------------------
作者:zqxLonely
来源:CSDN
原文:https://blog.csdn.net/zqxlonely/article/details/18267811
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-05-13 16:10  天涯海角路  阅读(596)  评论(0)    收藏  举报