举一反三
- 以下程序的运行结果是______ class A{public int getNumber(int a){return a+1;}}class B extends A{public int getNumber(int a, char c){return a+2;} public static void main(String[] args) {B b=new B();System.out.println(b.getNumber(0));} }
- 下列哪个代码替换程序中的【代码 A: protected int getNumber( ) { return 100; } B: int getNumber( ) { return 100; } C: public int getNumber( ) { return 100; } D: int getNumber( ) { return 'a'+'b'; }
- 请说出E类中[代码1]和[代码2]的输出结果。 class A{ double f(int x, double y){ return x+y; } int f(int x,int y) { return x*y; } } public class E{ public static void main(String args[ ] ){ A a=new A(); System.out.println(a.f(10,10)) ; // [代码1] System.out.println(a.f (10,10.0)) ; // [代码2] } }
- 对于下列代码,下列哪个叙述是正确的? class A { public int i=0; A(int m) { i = 1; } } public class B extends A { B(int m) { i = 2; } public static void main(String args[]){ B b = new B(100); System.out.println(b.i); //【代码】 } }
- 请说出E类中【代码1】,【代码2】的输出结果。 interface A { double f(double x,double y); } class B implements A { public double f(double x,double y) { return x*y; } int g(int a,int b) { return a+b; } } public class E { public static void main(String args[]) { A a = new B(); System.out.println(a.f(3,5)); //【代码1】 B b = (B)a; System.out.println(b.g(3,5)); //【代码2】 } }
内容
- 0
下列代码的输出结果是( )interface Com{ int M=100; int on();}class A implements Com{ public int on(){ return Com.M; }}public class E{ public static void main(String args[]){ Com com=new A(); int m=com.on(); System.out.println(m); }}
- 1
请写出下列程序的输出结果。class A{public int f(int x) {return x+1;}}class B extends A{public int f(int x){return x*x;}}public class E{public static void main(String args[]){A a=new B();int m=a.f(10);System. out. println(m) ;}}
- 2
5.请说出E类中[代码1],[代码2]的输出结果依次是______ ,______ 。 interface Com { int add(int a,int b); }abstract class A { abstract int add(int a,int b);int g(int a,int b) { return a+b; }}class B extends A implements Com{ public int add(int a,int b) { return a+b; } int g(int a,int b) { return a*b; }}public class E {public static void main(String args[]) { B b = new B(); Com com = b; System.out.println(com.add(10,5)); //[代码1] A a = b; System.out.println(a.g(10,5)); }} //[代码2]
- 3
public class E4_1{ public static void main(String args[]) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6; System.out.println("a = " + a); //代码1 System.out.println("b = " + b); //代码2 System.out.println("c = " + c); //代码3 }}运行结果,代码1______ ,代码2______ ,代码3______ 。
- 4
给出下列代码的输出结果:public class E{public static void main(String args[]){System.out.println((int)'a');}}