请说出E类中【代码1】,【代码2】的输出结果。class A {double f(double x,double y) {return x+y;}}class B extends A {double f(int x,int y) {return x*y;}}public class E {public static void main(String args[]) {B b=new B();System.out.println(b.f(3,5));//【代码1】System.out.println(b.f(3.0,5.0)); //【代码2】}}【代码1】的输出结果【代码2】的输出结果
查看答案
说出下列B类中【代码1】,【代码2】的输出结果。class A {public int getNumber(int a) {return a+1;}}class B extends A {public int getNumber (int a) {return a+100;}public static void main (String args[]) {A a =new A();System.out.println(a.getNumber(10)); //【代码1】a = new B();System.out.println(a.getNumber(10)); //【代码2】}}【代码1】的输出结果【代码2】的输出结果
请说出E类中【代码1】~【代码4】的输出结果。class A {double f(double x,double y) {return x+y;}static int g(int n) {return n*n;}}class B extends A {double f(double x,double y) {double m = super.f(x,y);return m+x*y;}static int g(int n) {int m = A.g(n);return m+n;}}public class E {public static void main(String args[]) {B b = new B();System.out.println(b.f(10.0,8.0));//【代码1】System.out.println(b.g(3));//【代码2】A a = new B();System.out.println(a.f(10.0,8.0));//【代码3】System.out.println(a.g(3));//【代码4】}}【代码1】的输出结果【代码2】的输出结果【代码3】的输出结果【代码4】的输出结果
请说出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}}【代码1】的输出结果【代码2】的输出结果【代码3】的输出结果
public class A {public void start() {System.out.println("TestA");}}public class B extends A {public void start() {System.out.println("TestB");}public static void main(String[] args) {B b=new B();A a=b;a.start();}}程序运行的结果是