1. 下列代码的运行结果是: public class GoTest { public static void main(String[] args) { Sente a = new Sente(); a.go(); Goban b = new Goban(); b.go(); Stone c = new Stone(); c.go(); } } class Sente implements Go { public void go() { System.out.println(“go in Sente”); } } class Goban extends Sente { public void go() { System.out.println(“go in Goban”); } } class Stone extends Goban implements Go { } interface Go { public void go(); } A. go in Goban go in Sente go in Sente B. go in Sente go in Sente go in Goban C. go in Sente go in Goban go in Goban D. go in Goban go in Goban go in Sente 正确答案:C 2. A类中有一个方法:protected int print(String str){},B类继承A类,以下方法能在B类中重写A类中print()方法的是: ()。 A.
public int print(String str){}
B.
private int print(String str){}
C.
private void print(String str){}
D.
public void print(String str){}
正确答案:A 3. List类的对象list中的元素为:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],现在想返回该list对象的子集合[5,6,7,8],需要做的操作是: A. list.subList(5, 8); B. list.subList(5, 9); C. list.subList(4, 8); D. list.subList(4, 9); 正确答案:B 4. 下列代码的运行结果是: String test = “Test A. Test B. Test C.”; String regex = “\\.\\s*”; String[] result = test.split(regex); for (String s : result) System.out.print(s + ” “); A. Test A Test B Test C
B. Test A. Test B. Test C.
C. Test . Test . Test .
D. A. B. C.
正确答案:A 5.
运行下面的程序: int a = 100; int b = 200; a = a + b; b = a – b; a = a – b;
System.out.println(“a=” + a + “, b=” + b); 输出的结果是:()。 A. a=100, b=300 B. a=100, b=200 C. a=200, b=100 D. a=300, b=200 正确答案:C 6.
类A,B和C的定义如下: public class A { public void f() { System.out.println(“A.f()”); } } public class B extends A { public void f() { System.out.println(“B.f()”); } } public class C { public void g(A a) { System.out.println(“g(A a)”);
a.f(); } public void g(B b) { System.out.println(“g(B b)”); b.f(); }
} 运行下面程序: C c = new C(); A a = new B(); c.g(a); 输出的结果是:()。 A. g(A a)
System.arraycopy(oneArr, p, threeArr, p + q, oneArr.length – p);
}
else if (q < twoArr.length) {
System.arraycopy(twoArr, q, threeArr, p + q, twoArr.length – q);
} System.out.println(Arrays.toString(threeArr)); 输出的结果是:()。 A. [2,11,26,27,37,44,48,60,19,35,49,55,58,75,83,84,91,93]; B. [2,11,19,26,27,35,37,44,48,49,55,58,60,75,83,84,91,93]; C. [19,35,49,55,58,75,83,84,91,93,2,11,26,27,37,44,48,60]; D. [2,19,11,35,26,49,27,55,37,58,44,75,48,83,60,84,91,93]; 正确答案:B 11.
请看下列代码:
public static void main(String[] args) {
<插入代码>
set.add(new Integer(2));
set.add(new Integer(1));
System.out.println(set);
}
如果想保证程序的输出结果是[1,2],那么<插入代码>处应填入的代码是()。 A.
Set set = new TreeSet(); B.
Set set = new HashSet(); C.
Set set = new SortedSet(); D.
Set set = new LinkedHashSet(); 正确答案:A 12.
仔细分析下列代码,请指出错误的行()。
public class SomeThing{
private String str;
public int addOne(final int x){
return ++x;
} } A.
public class SomeThing B.
private String str;
C.
public int addOne(final int x)
D.
return ++x;
正确答案:D 13.
下列代码的输出结果是()
public static void main(String[] args) {
String test = “a1b2c3″;
String[] tokens = test.split(“\\d”);
for (String s : tokens)
System.out.print(s + ” “);
} A.
a b c B.
1 2 3 C.
a1b2c3 D.
a1 b2 c3 正确答案:A 14. 请看下列代码: class Payload { private int weight; public Payload(int wt) { weight = wt; } public Payload() {} public void setWeight(int w) { weight = w; } public String toString() { return Integer.toString(weight); } } public class TestPayload { static void changePayload(Payload p) { <插入代码> } public static void main(String[] args) { Payload p = new Payload(); p.setWeight(1024); changePayload(p); System.out.println(“The value of p is ” + p); } } 假设运行后输出“The value of p is 420”,那么<插入代码>处应填入代码是: A. p.setWeight(420); B. Payload.setWeight(420); C. p = new Payload(420); D. p = new Payload(); p.setWeight(420); 正确答案:A 15. 下列代码的输出结果是: String str1 = “WhatisJava”; String str2 = “WhatisJava”; System.out.print(str1.equals( str2)); System.out.print(“,”); String str3 = new String(“WhatisJava”); System.out.println(str1.equals(str3)); A. true,false B. false,false C. false,true D. true,true 正确答案:D 16. 下列代码的输出结果是: public class Yikes { public static void go(Long n) { System.out.println(“Long “); } public static void go(Short n) { System.out.println(“Short “); } public static void go(int n) { System.out.println(“int “); } public static void main(String[] args) { short y = 6; long z = 7; go(y); go(z); } } A. Long Long B. Short Long C. int Long D. int int 正确答案:C 17. 下列代码的输出结果是: class Cup { } class PoisonCup extends Cup { public void takeCup(Cup c) { if (c instanceof PoisonCup) { System.out.println(“Inconceivable!”); } else if (c instanceof Cup) { System.out.println(“Dizzying intellect!”); } else { System.exit(0); } } } public class TestCup { public static void main(String[] args) { Cup cup = new PoisonCup(); PoisonCup poison=new PoisonCup(); poison.takeCup(cup); } } A. Inconceivable! B. Dizzying intellect! C. 代码正常运行,但是无输出 D. 抛出运行时异常 正确答案:A 18.
有变量声明如下:
short b = 120;
下列语句中,错误的是()。 A.
short s = b; B.
int i = b; C.
byte s1 = b; D.
long l = b; 正确答案:C 19. 下列关于IDE开发环境Eclipse,说法错误的是:()。 A. Eclipse可以通过插件(plugin)的方式扩展其功能。 B. Eclipse联盟是由IBM公司捐资组建的。 C. Eclipse使用了SWT图形界面技术。 D. Eclipse的运行不需要有JRE的支持。 正确答案:D 20. 下列选项中的类,能正确实现java.lang.Runnable接口和java.lang.Clonable接口的是()。 A.
public class Session implements Runnable, Clonable {
public void run();
public Object clone();
} B.
public class Session implements Runnable, implements Clonable {
public void run() { / do something */ }
public Object clone() { / make a copy */ }
} C.
public class Session implements Runnable, Clonable {
public void run() { / do something */ }
public Object clone() { /* make a copy */ }
} D.
public class Session extends Runnable, Clonable {
public void run() ;
public Object clone();
} 正确答案:C 21. 下面关于final说法正确的是:()。 A.
final修饰类时,该类能被继承。
B.
final修饰方法时,该方法能被重写。
C.
当使用static final 修饰的常量时,将采用编译期绑定的方式。
D.
当使用final和abstract共同修饰一个类时,final应至于abstract之前。
正确答案:C 22.
下列代码的输出结果是()。
public static void main(String[] args) {
int[] one=new int[]{4,6,8};
int[] two=new int[]{1,3,5,7,9};
System.arraycopy(one, 1, two, 2, 2);
System.out.println(Arrays.toString(two));
} A.
[1, 3, 7, 4, 6] B.
[1, 3, 5, 7, 8] C.
[1, 3, 5, 6, 9] D.
[1, 3, 6, 8, 9] 正确答案:D 23.
下列代码运行的结果是()。 public class Base {
public static final String FOO = “foo”;
public static void main(String[] args) {
Base b = new Base();
Sub s = new Sub();
System.out.print(Base.FOO);
System.out.print(Sub.FOO);
System.out.print(b.FOO);
System.out.print(s.FOO);
System.out.print(((Base) s).FOO);
}
}
class Sub extends Base {
public static final String FOO = “bar”;
} A.
foofoofoofoofoo B.
foobarfoobarbar C.
foobarfoofoofoo D.
foobarfoobarfoo 正确答案:D 24. 下列不属于Java运算符的是()。 A.
!=
B.
<>
C.
>>
D.
<<
正确答案:B 25.
运行下列程序:
String str = “**oracle***oracle*****oracle***”;
String str1 = “oracle”;
int index = 0;
while ((index = str.indexOf(str1, index)) != -1) {
System.out.print(index+””);
index += str1.length();
} 控制台输出的结果是:()。 A.
1 10 21
B.
2 11 22
C.
3 13 23
D.
5 13 22
正确答案:B 26. 下列表达式中,可以得到精确结果的是()。 A. double d1 = 3.0 – 2.6; B. double d4 = 2.5 * 1.5; C. double d2 = 30/300; D. double d3 = 1/2 + 0.5; 正确答案:B 27. 请看下列代码: interface Foo { int bar(); } public class Sprite { public int fubar(Foo foo) { return foo.bar(); } public void testFoo() { fubar( <插入代码> ); } } 使类Sprite编译通过,在<插入代码>处应填入的代码是: A. Foo { public int bar() { return 1; } } B. new Foo { public int bar() { return 1; } } C. new Foo() { public int bar(){return 1; } } D. new class Foo { public int bar() { return 1; } } 正确答案:C 28. 运行下面的程序:
Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 2012); c.set(Calendar.MONTH, Calendar.SEPTEMBER); c.set(Calendar.DATE, 31); SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
System.out.println(sdf.format(c.getTime())); 输出的结果是:()。 A. 2012-10-1 B. 2012-10-01 C. 2012-09-30 D. 2012-9-30 正确答案:B 29.
编译和运行以下代码的结果为()。
public class MyMain{
public static void main(String argv){
System.out.println(“Hello cruel world”);
}
} A.
编译错误 B.
运行输出 “Hello cruel world” C.
编译无错,但运行时指示没有定义构造方法 D.
编译无错,但运行时指示没有正确定义main方法 正确答案:D 30.
运行下面程序:
public class Foo {
public static void main(String[] args) {
StringBuffer a=new StringBuffer(“A”);
StringBuffer b=new StringBuffer(“B”);
operator(a,b);
System.out.println(a+”,”+b);
}
public static void operator(StringBuffer x,StringBuffer y){
x.append(y);
y=x;
}
} 输出的结果是:()。 A.
A,B
B.
A,A
C.
B,B
D.
AB,B
正确答案:D 31.
分析如下代码,输出结果为()。
public static void main(String[] args) {
int i = 0;
boolean re = false;
re = ((++i) + i == 2) true : false;
System.out.println(“i=” + i + “,re=”+re);
} A.
i=1,re=true B.
i=0,re=true C.
i=1,re=false D.
i=0,re=false 正确答案:A 32. 数据类型int、char和double所占用内存字节数分别是:()。 A. 4、2和8 B. 2、2和4 C. 2、1和8 D. 4、4和4 正确答案:A 33.
下列代码的输出结果是:()。
public class StaticFoo {
int num;
static int x;
public static void main(String[] args) {
StaticFoo foo1 = new StaticFoo ();
foo1.num++;
foo1.x++;
StaticFoo foo2 = new StaticFoo ();
foo2.num++;
foo2.x++;
StaticFoo foo3 = new StaticFoo ();
foo3.num++;
foo3.x++;
StaticFoo.x++;
System.out.print(foo3.num+”,”);
System.out.println(foo3.x);
} } A.
3,3
B.
1,3
C.
3,4
D.
1,4
正确答案:D 34. 下列代码的运行结果是: public class WrappedString { private String s; public WrappedString(String s) { this.s = s; } public static void main(String[] args) { HashSet
List
B.
ArrayList
C.
Set
D.
Collection
正确答案:C 36. 请看下列代码: public abstract class Shape { int x; int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } 下列选项中能正确使用Shape类的是: A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public class Circle extends Shape { private int radius; public void draw() {/* code here */} } 正确答案:BD 37. 下面的方法属于StringBuffer的是:()。 A. size B. insert C. delete D. length 正确答案:BCD 38. 已知类Foo的定义如下: public class Foo { int value; Foo(int value) { this.value = value; } public boolean equals(Object obj) { if (obj instanceof Foo) { Foo foo = (Foo) obj; return value == foo.value; } else { return false; } } 运行下面程序段: ArrayList list = new ArrayList(); HashSet set = new HashSet(); list.add(new Foo(1)); set.add(new Foo(1)); System.out.println(《插入代码》); 如果控制台输出的结果是true,false,那么《插入代码》处应填入的代码是: A. list.contains(new Foo(1)) + “,”+ set.contains(new Foo(1)) B. set.contains(new Foo(1)) + “,”+ list.contains(new Foo(1)) C. new Foo(1).equals (new Foo(1)) + “,”+ list.contains(new Foo(1)) D. new Foo(1).equals (new Foo(1)) + “,”+ set.contains(new Foo(1)) 正确答案:AD 39.
查看如下代码: class A {
protected int method (int a, int b) {
return 0;
}
} 下列选项中,可以在 A 的子类中使用的是()。 A. public int method (int a, int b) { return 0; } B. private int method(int a, int b) { return 0; } C. private int method(int a, long b) { return 0; } D. public short method(int a, int b) { return 0; } 正确答案:AC 40. 下列逻辑表达式,值为false的是()。 A. “abc,,,bcd,,def,efg,,”.split(“[,]+”).length == 4; B. “1st456″.matches(“\\d[a-z&&[^et]]{2,8}[0-9]+”); C. “abcdefghijklmnopqrstuvwxyz”.substring(5,26).length() == 20; D. “whatisjava”.equals(null); 正确答案:BCD 41.