给出下面一段程序,选择运行结果() public class X{ public static void main(String[] args){ String names[] = new String[5]; for(int x=0; x<args.length; x++) names[x]=args[x]; System.out.println(names[2]); } } 命令行执行:java X 结果是下面哪一个?
A.names
B.b
C.null
D.运行出现异常
第1题:
下面程序的输出结果为( )。 public class Test { public static void main (String args[]) { String X="ABCD"; String Y="EFG"; X=X.substring (X.length()-Y.length()); System.out.println(X); } }
A.ABC
B.BCD
C.EFG
D.ABCDEFG
第2题:
执行下面程序,显示的结果为( )。 public class Test { public static void main (String args[]) { Test t=newTest(); System.out.println (Loverload ("2","3")); } int overload (intx,int y) {return x+y;} String overload (String x,Stnng y){return x+y;} }
A.2
B.3
C.5
D.23
第3题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第4题:
下列语序列执行后,输出的结果是______。 public class ex26 { public static void main(String[] args) { int x=l5; x/=x%5+x*(x-x%10); System.out.println(x); } }
A.0
B.5
C.10
D.15
第5题:
下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }
A.x=10
B.x=20
C.x=6
D.编译不通过
第6题:
A.跳出循环,无输出
B.0121
C.01
D.0123
第7题:
执行如下语句之后,输出的结果是______。 public class ex36 { public static void main(String[] args) { int x=-6, y=6; x=x+y--; System.out.println (x); } }
A.-12
B.12
C.-1
D.0
第8题:
import java.util.*; class Banana3 { public static void main(String [] args) { int x = 2; Banana3 b = new Banana3(); b.go(x); } static { x += x; } void go(int x) { ++x; System.out.println(x); } } 结果为:()
第9题:
现有: class Top { static int X=l; public Top() { x*=3; } } class Middle extends Top { public Middle() {x+=l; } public static void main(String [] args) { Middle m=new Middle(); System.out.println (x); } } 结果是什么?()
第10题:
class TestMain { static int x = 2; static { x = 4; } static public void main(String[] args) { int y = x + 1; System.out.println(y); } } 和命令行: java TestMain 结果为:()
第11题:
下面哪些main方法可用于程序执行()
第12题:
3
5
编译失败
运行时异常被抛出
第13题:
阅读下面程序 public class Test3 { public static void main(String[] args) { int x=3,y=4,z=5; String s="xyz": System.out.println(s+x+y+z); } } 程序运行的结果是
A.xyz12
B.xyz345
C.xyzxyz
D.12xyz
第14题:
阅读下面程序 public class Test3 { public static void main(String args[]){ int x=3, y=4, z=5; String s="xyz"; System.out.primln(s+x+y+z); } } 程序运行的结果是
A.xyzl2
B.xyz345
C.xyzxyz
D.12xyz
第15题:
执行下面的程序段后,x的值为( )。 public class Sun { public static void main(String args[ ]) { int x=5; for(int i=l;i<=20;i=i+2) x=x+i/5; System.out.println(x); } }
A.21
B.22
C.23
D.24
第16题:
下面程序段的输出结果为( )。 package test; public class ClassA { int x=20: static int y=6; public static void main(String args[]) { ClassB b=new ClassB; go(10); System.out.println("x="+b.x); } } class ClassB { int X; void go(int y) { ClassA a=new ClassA; x=a.Y ; } }
A.x=10
B.x=20
C.x=6
D.编译不通过
第17题:
执行如下语句之后,输出的结果是______。 public class ex24 { public static void main(String[] args) { int x=5,y=3; x+=X-- *--y; System.out.println{x); } }
A.0
B.1
C.true
D.false
第18题:
执行如下语句之后,输出的结果是 ( )public class ex1{ public static void main(String[]args){ int x=5,y=3, x+=x--*--y System.out.println(x); }}
A.12
B.8
C.15
D.16
第19题:
A. 3
B. 4
C.5
D.6
E.7
第20题:
现有: class TestMain { static int x = 2; static { x = 4; } static public void main(String[] args) { int y = x + 1; System.out.println(y); } } 和命令行: java TestMain 结果为:()
第21题:
现有: class WhileTests { public static void main (String [] args) { int X=5; while (++x<4) { --x; } System.out.println( "x="+x); } } 结果是什么?()
第22题:
class WhileTests { public static void main(String [] args) { int x = 5; while (++x 〈 3) { --x; } System.out.println("x = " + x); } } 结果是什么?()
第23题:
55
56
65
66
第24题:
y=10,x=5
y=11,x=6
y=12,x=7
y=11,x=7