1.写出以下程序的运行结果。
class A {
void testOverload(int i) {
System.out.println("int");
}
void testOverload(String s) {
System.out.println("String");
}
public static void main(String args[]) {
A a = new A();
char ch = 'x';
a.testOverload(ch);
}
}
结果:int
2.阅读以下程序,写出输出结果。
class C {
public C() {
aMethod();
}
public void aMethod() {
System.out.println("in First class");
}
}
public class B extends C {
public void aMethod() {
System.out.println("in Second class");
}
public static void main(String[] args) {
new B();
}
}
结果:in Second class
3.写出以下程序的运行结果。
package com.anbo.lian;
public class C {
public static void main(String[] args) {
Loop: for (int i = 2; i < 10; i++) {
for (int j = 2; j < i; j++) {
if (i % j == 0)
continue Loop;
}
System.out.print(i + " ");
}
}
}
结果:2 3 5 7
4.编译运行以下程序后,关于输出结果的说明正确的是(C)
package com.anbo.lian;
public class D {
public static void main(String args[]) {
int x = 4;
System.out.println("value is " + ((x > 4) ? 99.9 : 9));
}
}
A.输出结果为:value is 99.99 B.输出结果为:value is 9
C.输出结果为:value is 9.0 D.编译错误
5.阅读以下代码:
package com.anbo.lian;
public class B {
public static void main(String[] args) {
String s;
System.out.println("s=" + s);
}
}
输出结果应该是:( C )
A.代码得到编译,并输出“s=”
B.代码得到编译,并输出“s=null”
C.由于String s没有初始化,代码不能编译通过
D.代码得到编译,但捕获到 NullPointException异常
6.执行完以下代码int [] x=new int[10];后,以下哪项说明是正确的( A )
A.x[9]为0 B.x[9]未定义 C.x[10]为0 D.x[0]为空
7.关于以下程序段,正确的说法是( C )
1 String s1 = "a" + "b";
2 String s2 = new String(s1);
3 if (s1 == s2)
4 System.out.println("= = is succeeded");
5 if (s1.equals(s2))
6 System.out.println(".equals() is succeeded");
A.行4与行6都将执行 B.行4执行,行6不执行
C.行6执行,行4不执行 C.行4、行6都不执行
8.以下程序的运行结果是:( C )
package com.anbo.lian;
public class G {
public static void main(String args[]) {
int c;
c = 2;
System.out.println(c);
System.out.println(c++);
System.out.println(c);
}
}
结果:2 2 3
9.写出以下程序的运行结果。
package com.anbo.lian;
public class J {
public static void changestr(String str) {
str = "welcome";
}
public static void main(String[] args) {
String str = "1234";
changestr(str);
System.out.println(str);
}
}
结果:1234
1.写出以下程序的运
行结果。
package com.anbo.lian;
public class M {
static boolean foo(char c) {
System.out.print(c);
return true;
}
public static void main(String[] args) {
int i = 0;
for (foo('a'); foo('b') &;&; (i < 2); foo('c')) {
i++;
foo('d');
}
}
}
结果:abdcbdcb
2.关于以下
程序代码的说明正确的是( D )
package com.anbo.lian;
public class I {
private static int x = 100;
public static void main(String args[]) {
I hs1 = new I();
(5) hs1.x++;
I hs2 = new I();
hs2.x++;
hs1 = new I();
hs1.x++;
(10) I.x--;
System.out.println("x=" + x);
}
}
A、 5行不能通过编译,因为引用了私有静态变量
B、 10行不能通过编译,因为x是私有静态变量
C、 程序通过编译,输出结果为:x=103
D、 程序通过编译,输出结果为:x=102
3.当下列程序执行时,其输出结果是( B )
int x = 5;
int y = 2;
System.out.println(x+ y + "k");
A、5k
B、7k
C、52k
D、3k
4.编译和运行下面