执行下列程序段后a和b的值为 class AB{ int a , b ; public void init(int x){ a = x ; int b = 5 ; } public void display(){ System.out.println("a = "+a+" b = "+b); } } public class ABTest{ public static void main(String[] args){ AB ab = new AB(); ab.init(6); ab.display() ; } }
A: a = 5 b = 5
B: a = 0 b = 0
C: a = 6 b = 5
D: a = 6 b = 0
A: a = 5 b = 5
B: a = 0 b = 0
C: a = 6 b = 5
D: a = 6 b = 0
举一反三
- 请阅读下面的程序 Public class Test { public static void main(String[] args) { int a = 0; int b = 0; for (int i = 1; i <= 5; i++) {
- 以下程序运行结果是 public class Test { public static void main(String[] args) { int a=1,b[]={2}; add(a); add(b); System.out.println(a+","+b[0]); } static int add(int x){ x++; return x; } static void add(int[] x){ x[0]++; } }
- 下面程序运行结果为___________________。public class MyClass{ private static int a = 19; public static void modify(int a){ a = a + 5;} public static void main(String[] args){ modify(a); System.out.println(a); }}
- 以下程序运行结果为: public class Q { public static void main(String argv[]) { int anar[]= new int[5]; System.out.println(anar[0]); } }
- 智慧职教: 下列代码执行之后,变量x的值为( ) public class Test { public static void main (String[] args) { int x=5; int m=0; x+=x+++(x+++m); System.out.println(x); } }