题目内容
阅读程序,请说出E类中【代码1】~【代码3】的输出结果。class A {int m;int getM() {return m;}int seeM() {return m;}}class B extends A {int m ;int getM() {return m+100;}}public class E {public static void main(String args[]) {B b =new B();b.m=20;System.out.println(b.getM()); //【代码1】A a = b;a.m = -100; // 上转型对象访问的是被隐藏的mSystem.out.println(a.getM()); //【代码2】上转型对象调用的一定是子类重写的getM()方法System.out.println(b.seeM()); //【代码3】子类继承的seeM()方法操作的m是被子类隐藏的m}}
查看答案
搜索结果不匹配?点我反馈