阅读下面的程序,下面说法中正确的是() public class Test{ public static int x = 10; public static int y = 20; public static void main(String[] args){ public int x = 100; public boolean b = true; System.out.println("x = "+x); System.out.println("b = "+b); System.out.println("y = "+y); } }
A: 变量y是局部变量,b是成员变量。
B: 不能输出y的值,这个程序运行后输出的结果是 x=10 b=true
C: 这个程序运行后输出的结果是 x=10 b=true y=20
D: 这个程序运行后输出的结果是 x=100 b=true y=20
A: 变量y是局部变量,b是成员变量。
B: 不能输出y的值,这个程序运行后输出的结果是 x=10 b=true
C: 这个程序运行后输出的结果是 x=10 b=true y=20
D: 这个程序运行后输出的结果是 x=100 b=true y=20
举一反三
- 请阅读下面的程序 public class Test { public static void main(String[] args) { int x; int y; for (x = 1, y = 1; x <= 100; x++) { if (y >= 20) { break; } if (y % 3 == 1) { y += 3; continue; } y -= 5; } System.out.println(“x=” + x + “,y=” + y); } } 下列选项中,哪一个是程序的运行结果( )
- (6-6)请阅读程序,写出程序运行结果。 class Test{ static int x=10; int y=99; { y=y+10; } static { x=x+5; } { y=y+10; } static { x=x+5; } public Test() {//构造方法 x=x+5; } { System.out.println(x*y); } } public class Demo11 { public static void main(String[] args) { Test t1=new Test(); Test t2=new Test(); } }
- 执行下列程序,输出结果为()。 public class B{ public static void main(String[] args) { int x = 5; double y = 10.5f; float z = (float)(x*y); System.out.println(z); } }
- 写出下面程序运行结果。public class Demo public static void main(String args[]) int x = 5, y = 10, r = 5 switch (x y) case 15: r = x case 20: r -= y case 25: r = x / y default: r = r System.out.println(r)
- 阅读下列程序,请写出该程序的输出结果。 class B{ int b; B(int x){b=x;System.out.println("b="+b); } } class A extends B{ int a; A(int x,int y){ super(x); a=y; System.out.println("b="+b+",a="+a); } } public class a32{ public static void main(String[]args){ A obj=new A(1,2); } }