举一反三
- public class test { public static void main(String args[]) { int m=0; for ( int k=0;k<2;k++) method(m++); System.out.println(m); } public static void method(int m) { System.out.print(m); } }
- 以下代码的输出结果?public class Test{public sta...tring m){m=m+2;}}
- 下列代码的输出结果是( )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); }}
- 给出下列代码,如何使成员变量m被方法fun()直接访问?class Test { private int m; public static void fun( ) { ... }} A.将 private int m 改为protected int m B.将private int m 改为public int m C.将private int m改为static int m D.将private int m改为int m
- 给出如下代码: class Test{ private int m(){ ...... } public static void fun() { ...... } } 如何使成员函数m() 被函数fun()直接访问 A: 将private int m() 改为protected int m() B: 将private int m() 改为 public int m() C: 将private int m() 改为 static int m() D: 将private int m() 改为 int m()
内容
- 0
给出下列【代码】注释标注的代码的输出结果。abstract class A {abstract int get(int a,int b);}public class E {public static void main(String args[]) {A a=new A() {public int get(int a,int b){return a+b;}};int m = a.get(2,5);a=new A() {public int get(int a,int b){return a*b;}};int n = a.get(2,5);System.out.printf("%d:%d",m,n);//【代码】}}
- 1
给出下列代码,如何使成员变量m 被方法fun()直接访问? class Test { private int m; public static void fun() { } }
- 2
下列代码中,将引起一个编译错误的行是______。 1)public class Test{ 2) int m,n; 3) public Test(){} 4) public Test(int a){m=a;} 5) public static void main(String args[]){ 6) Test t1,t2; 7) int j,k; 8) j=0;k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12) }
- 3
给出下面代码段 1) public class Test { 2) int m, n; 3) public Test() {} 4) public Test(int a) { m=a; } 5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k; 8) j=0; k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12) } 哪行将引起一个编译时错误?
- 4
请写出下列程序的输出结果。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) ;}}