java程序处理ibitis 关键字_Java笔试题库选择题

Java笔试题库选择题

2011 - 07 - 21 更新

第一部分:选择题

1) 哪个不是面向对象的特征 ( )

a) 封装性 b) 继承性 c) 多态性 d) 健壮性

2) 编译JAVA文件的命令是( )。

a) Java b) Javac c) Javadb d) Javaw

3) JAVA源文件的扩展名是( )。

a) Class b) exe c) java d) dll

4) JAVA内部使用的编码格式是( )。

a) UTF-8 b) ASCII c) UNICODE d) ISO8859-1

5) 下列变量名称不合法的是( )

a) Index b) $bc3& c) _cccde d) 34#bc5

6) 下边对基本数据类型的说明正确的是( )

a) Int可以自动转换为BYTE类型

b) DOUBLE类型的数据占用2个字节

c) JAVA中一共有4类8种基本数据类型

d) JAVA中一共有3类8种基本数据类型

7) 下列不是JAVA关键字的是( )

a) goto b) if c) count d) private

8) 下列变量声明中正确的是( )

a) Float f = 3.13 b) Boolean b = 0

c) Int number = 5 d) Int x Byte a = x

9) public void go() {

String o = “”;

z:

for(int x = 0; x < 3; x++) {

for(int y = 0; y < 2; y++) {

if(x==1) break;

if(x==2 && y==1) break z;

o = o + x + y;

}

}

System.out.println(o);

}

程序的执行结果是( )

a) 00

b) 0001

c) 000120

d) 00012021

e) Compilation fails.

f) An exception is thrown at runtime

10) class Payload {

private int weight;

public Payload (int w) { weight = w; }

public void setWeight(int w) { weight = w; }

public String toString() { return Integer.toString(weight); }

}

public class TestPayload {

static void changePayload(Payload p) { /* insert code */ }

public static void main(String[] args) {

Payload p = new Payload(200);

p.setWeight(1024);

changePayload(p);

System.out.println("p is " + p);

}

}

Insert code处写入哪句话, 可以使程序的输出结果是420( )

a) p.setWeight(420);

b) p.changePayload(420);

c) p = new Payload(420);

d) Payload.setWeight(420);

e) p = Payload.setWeight(420);

11) void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) {

obj.wait();

obj.notify();

}

}这个程序片段的运行结果是什么( )

a) This code can throw an InterruptedException.

b) This code can throw an IllegalMonitorStateException.

c) This code can throw a TimeoutException after ten minutes.

d) Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.

12) public class Threads2 implements Runnable {

public void run() {

System.out.println("run.");

throw new RuntimeException("Problem");

}

public static void main(String[] args) {

Thread t = new Thread(new Threads2());

t.start();

System.out.println("End of method.");

}

}

运行结果是什么,请选择2个( )

a) java.lang.RuntimeException: Problem

b) run. java.lang.RuntimeException: Problem

c) End of method. java.lang.RuntimeException: Problem

d) End of method. run. java.lang.RuntimeException: Problem

e) run. java.lang.RuntimeException: Problem End of method.

13) 下边哪2句话的描述是正确的( )

a) It is possible for more than two threads to deadlock at once

b) The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.

c) Deadlocked threads release once their sleep() method's sleep duration has expired.

d) Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly.

e) It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.

f) f a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().

14) public class Threads2 implements Runnable {

public void run() {

System.out.println("run.");

throw new RuntimeException("Problem");

}

public static void main(String[] args) {

Thread t = new Thread(new Threads2());

t.start();

System.out.println("End of method.");

}

}程序运行结果是,选择2个( )

a) java.lang.RuntimeException: Problem

b) run. java.lang.RuntimeException: Problem End of method

c) End of method. java.lang.RuntimeException: Problem

d) End of method. run. java.lang.RuntimeException: Problem

15) void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) {

obj.wait();

obj.notify();

}

}下列那句描述是正确的( )

a) This code can throw an InterruptedException.

b) This code can throw an IllegalMonitorStateException.

c) This code can throw a TimeoutException after ten minutes.

d) This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".

16) 11. class PingPong2 {

synchronized void hit(long n) {

for(int i = 1; i < 3; i++)

System.out.print(n + "-" + i + " ");

}

}

public class Tester implements Runnable {

static PingPong2 pp2 = new PingPong2();

public static void main(String[] args) {

new Thread(new Tester()).start();

new Thread(new Tester()).start();

}

. public void run() { pp2.hit(Thread.currentThread().getId()); }

}运行结果是( )

a) The output could be 5-1 6-1 6-2 5-2

b) The output could be 6-1 6-2 5-1 5-2

c) The output could be 6-1 5-2 6-2 5-1

d) The output could be 6-1 6-2 5-1 7-1

17) 1. public class Threads4 {

public static void main (String[] args) {

new Threads4().go();

}

public void go() {

Runnable r = new Runnable() {

public void run() { System.out.print("foo");

}

};

Thread t = new Thread(r);

t.start();

t.start();

}

}运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) The code executes normally and prints "foo".

d) The code executes normally, but nothing is printed.

18) 11. public class Barn {

public static void main(String[] args) {

new Barn().go("hi", 1);

new Barn().go("hi", "world", 2);

}

public void go(String... y, int x) {

System.out.print(y[y.length - 1] + " ");

}

}运行结果是( )

a) hi hi

b) hi world

c) Compilation fails

d) An exception is thrown at runtime.

19) 10. class Nav{

. public enum Direction { NORTH, SOUTH, EAST, WEST }

}

public class Sprite{

// insert code here

}哪句代码放到14行,程序可以正常编译( )

a) Direction d = NORTH;

b) Nav.Direction d = NORTH;

c) Direction d = Direction.NORTH;

d) Nav.Direction d = Nav.Direction.NORTH;

20) 11. public class Rainbow {

public enum MyColor {

RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);

private final int rgb;

MyColor(int rgb) { this.rgb = rgb; }

public int getRGB() { return rgb; }

};

public static void main(String[] args) {

// insert code here

}

}哪句代码放到19行,程序可以正常编译( )

a) MyColor skyColor = BLUE;

b) MyColor treeColor = MyColor.GREEN;

c) Compilation fails due to other error(s) in the code.

d) MyColor purple = MyColor.BLUE + MyColor.RED;

21) 5. class Atom {

Atom() { System.out.print("atom "); }

}

class Rock extends Atom {

Rock(String type) { System.out.print(type); }

}

public class Mountain extends Rock {

Mountain() {

super("granite ");

new Rock("granite ");

}

public static void main(String[] a) { new Mountain(); }

}运行结果是( )

a) Compilation fails

b) atom granite granite

c) An exception is thrown at runtime.

d) atom granite atom granite

22) 1. interface TestA { String toString(); }

public class Test {

public static void main(String[] args) {

4System.out.println(new TestA() {

public String toString() { return "test"; }

});

}

}运行结果是( )

a) test

b) null

c) An exception is thrown at runtime.

d) Compilation fails because of an error in line 1.

23) 11. public static void parse(String str) {

try {

float f = Float.parseFloat(str);

} catch (NumberFormatException nfe) {

f = 0; } finally {

17. System.out.println(f);

}

}

public static void main(String[] args) {

parse("invalid");

}运行结果是( )

a) 0.0

b) Compilation fails.

c) A ParseException is thrown by the parse method at runtime

d) A NumberFormatException is thrown by the parse method at runtime

24) 1. public class Blip {

protected int blipvert(int x) { return 0; }

}

class Vert extends Blip {

// insert code here

}下列哪5个方法放到代码第五行,可以让程序编译正确,选择5个( )

a) public int blipvert(int x) { return 0; }

b) private int blipvert(int x) { return 0; }

c) private int blipvert(long x) { return 0; }

d) protected long blipvert(int x) { return 0; }

e) protected int blipvert(long x) { return 0; }

f) protected long blipvert(long x) { return 0; }

g) protected long blipvert(int x, int y) { return 0; }

25) 1. class Super {

private int a;

protected Super(int a) { this.a = a; }

} ...

class Sub extends Super {

public Sub(int a) { super(a); }

public Sub() { this.a = 5; }

}下列哪2条语句是正确的( )

a) Change line 2 to: public int a;

b) Change line 2 to: protected int a;

c) Change line 13 to: public Sub() { this(5); }

d) Change line 13 to: public Sub() { super(5); }

e) Change line 13 to: public Sub() { super(a); }

26) package test;

class Target {

public String name = "hello";

}如果可以直接修改和访问name这个变量,下列哪句话是正确的( )

a) any class

b) only the Target class

c) any class in the test package

d) any class that extends Target

27) 11. abstract class Vehicle { public int speed() { return 0; }

class Car extends Vehicle { public int speed() { return 60; }

class RaceCar extends Car { public int speed() { return 150; } ...

RaceCar racer = new RaceCar();

Car car = new RaceCar();

Vehicle vehicle = new RaceCar();

System.out.println(racer.speed() + ", " + car.speed()

+ ", " + vehicle.speed());运行结果是( )

a) 0, 0, 0

b) 150, 60, 0

c) Compilation fails

d) 150, 150, 150

e) An exception is thrown at runtime

28) 5. class Building { }

public class Barn extends Building {

public static void main(String[] args) {

Building build1 = new Building();

Barn barn1 = new Barn();

Barn barn2 = (Barn) build1;

Object obj1 = (Object) build1;

String str1 = (String) build1;

Building build2 = (Building) barn1;

} 15. }运行结果是( )

a) If line 10 is removed, the compilation succeeds.

b) If line 11 is removed, the compilation succeeds

c) If line 12 is removed, the compilation succeeds.

d) If line 13 is removed, the compilation succeeds.

e) More than one line must be removed for compilation to succeed.

29) 29.Given:

class Money {

private String country = "Canada";

public String getC() { return country; }

}

class Yen extends Money {

public String getC() { return super.country; }

}

public class Euro extends Money {

public String getC(int x) { return super.getC(); }

public static void main(String[] args) {

System.out.print(new Yen().getC() + " " + new Euro().getC());

} 33. }运行结果是( )

a) Canada

b) null Canada

c) Canada null

d) Compilation fails due to an error on line 26

e) Compilation fails due to an error on line 29

30) 13. import java.io.*;

class Food implements Serializable {int good = 3;}

class Fruit extends Food {int juice = 5;}

public class Banana extends Fruit {

int yellow = 4;

public static void main(String [] args) {

Banana b = new Banana(); Banana b2 = new Banana();

b.serializeBanana(b); // assume correct serialization

b2 = b.deserializeBanana(); // assume correct

System.out.println("restore "+b2.yellow+ b2.juice+b2.good);

}

// more Banana methods go here

}运行结果是( )

a) restore 400

b) restore 403

c) restore 453

d) Compilation fails.

e) An exception is thrown at runtime.

31) 11. double input = 314159.26;

NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);

String b;

//insert code here

下列哪条语句可以设置变量b的值为314.159,26( )

a) .b = nf.parse( input );

b) b = nf.format( input );

c) b = nf.equals( input );

d) b = nf.parseObject( input );

32) 1. public class TestString1 {

public static void main(String[] args) {

String str = "420";

str += 42;

System.out.print(str);

} 7. }输出结果是( )

a) 42 b) 420 c) 462 d) 42042

33) 22. StringBuilder sb1 = new StringBuilder("123");

String s1 = "123";

// insert code here

System.out.println(sb1 + " " + s1);

下列哪句代码放到程序的第24行,可以输出"123abc 123abc"( )

a) sb1.append("abc"); s1.append("abc");

b) sb1.append("abc"); s1.concat("abc");

c) sb1.concat("abc"); s1.append("abc");

d) sb1.concat("abc"); s1.concat("abc");

e) sb1.append("abc"); s1 = s1.concat("abc");

f) sb1.concat("abc"); s1 = s1.concat("abc");

g) sb1.append("abc"); s1 = s1 + s1.concat("abc");

34) 1. public class LineUp {

public static void main(String[] args) {

double d = 12.345;

// insert code here

}

}下列哪句代码放到程序的第4行,可以输出| 12.345|? ( )

a) System.out.printf("|%7d| \n", d);

b) System.out.printf("|%7f| \n", d);

c) System.out.printf("|%3.7d| \n", d);

d) System.out.printf("|%3.7f| \n", d);

e) System.out.printf("|%7.3d| \n", d);

f) System.out.printf("|%7.3f| \n", d);

35) 11. public class Test {

public static void main(String [] args) {

int x = 5;

boolean b1 = true;

boolean b2 = false;

if ((x == 4) && !b2 )

System.out.print("1 ");

System.out.print("2 ");

if ((b2 = true) && b1 )

System.out.print("3 ");

}

}程序的输出结果是( )

a) 2

b) 3

c) 1 2

d) 2 3

e) 1 2 3

f) Compilation fails.

g) An exception is thrown at runtime.

36) 10. interface Foo {}

class Alpha implements Foo {}

class Beta extends Alpha {}

class Delta extends Beta {

public static void main( String[] args ) {

Beta x = new Beta();

// insert code here

} 18. }

下列哪句代码放到第16行,可以导致一个java.lang.ClassCastException( )

a) Alpha a = x;

b) Foo f = (Delta)x;

c) Foo f = (Alpha)x;

d) Beta b = (Beta)(Alpha)x;

37) 22. public void go() {

String o = "";

z:

. for(int x = 0; x < 3; x++) {

for(int y = 0; y < 2; y++) {

if(x==1) break;

if(x==2 && y==1) break z;

o = o + x + y;

}

}

System.out.println(o);

}当调用go方法时,输出结果是什么( )

a) 00

b) 0001

c) 000120

d) 000120221

38) 11. static void test() throws RuntimeException {

try {

System.out.print("test ");

throw new RuntimeException();

}

catch (Exception ex) { System.out.print("exception "); }

}

public static void main(String[] args) {

try { test(); }

catch (RuntimeException ex) { System.out.print("runtime "); }

System.out.print("end "); }程序运行结果是( )

a) test end

b) Compilation fails.

c) test runtime end

d) test exception end

e) .A Throwable is thrown by main at runtime

39) 33. try {

// some code here

} catch (NullPointerException e1) {

System.out.print("a");

} catch (Exception e2) {

System.out.print("b");

} finally {

System.out.print("c");

}如果程序的第34行会抛出一些异常,程序的运行结果是( )

a) a b) b c) c d) ac e) abc

40) 31. // some code here

try {

// some code here

} catch (SomeException se) {

// some code here

} finally {

// some code here

} 哪种情况下37行的代码会执行,请选择3个( )

a) The instance gets garbage collected.

b) The code on line 33 throws an exception.

c) The code on line 35 throws an exception.

d) The code on line 31 throws an exception.

e) The code on line 33 executes successfully.

41) 10. int x = 0;

int y = 10;

do {

y--; ++x;

} while (x < 5);

System.out.print(x + "," + y);

程序运行结果是( )

a) 5,6

b) 5,5

c) 6,5

d) 6,6

42) public class Drink {

public static void main(String[] args) {

boolean assertsOn = true;

assert (assertsOn) : assertsOn = true;

if(assertsOn) {

System.out.println("assert is on");

}

}

}程序运行结果是( )

a) no output

b) no output assert is on

c) assert is on

d) assert is on An AssertionError is thrown.

43) 11. Float pi = new Float(3.14f);

if (pi > 3) {

System.out.print(“pi is bigger than 3. “);

}

else { System.out.print(“pi is not bigger than 3. “);

}

finally {

System.out.println(“Have a nice day.”);

}程序运行结果是( )

a) Compilation fails.

b) pi is bigger than 3

c) An exception occurs at runtime.

d) pi is bigger than 3. Have a nice day.

e) pi is not bigger than 3. Have a nice day.

44) 1. public class Boxer1{

Integer i;

int x;

public Boxer1(int y) {

x = i+y;

System.out.println(x);

}

public static void main(String[] args) {

new Boxer1(new Integer(4));

}

}运行结果是( )

a) The value “4″ is printed at the command line.

b) Compilation fails because of an error in line 5.

c) A NullPointerException occurs at runtime.

d) A NumberFormatException occurs at runtime.

45) 1. public class Person {

private String name;

public Person(String name) { this.name = name; }

public boolean equals(Person p) {

return p.name.equals(this.name); 6. } 7. }

下列哪条语句是正确的( )

a) The equals method does NOT properly override the Object.equals method.

b) Compilation fails because the private attribute p.name cannot be accessed in line 5.

c) To work correctly with hash-based data structures, this class must also implement the hashCode method.

d) When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.

46) 1. public class Score implements Comparable {

private int wins, losses;

public Score(int w, int l) { wins = w; losses = l; }

public int getWins() { return wins; }

public int getLosses() { return losses; }

public String toString() {

return ““;

}

// insert code here

}下列哪句代码放到第9行,程序可以正确编译( )

a) public int compareTo(Object o){/*more code here*/}

b) public int compareTo(Score other){/*more code here*/}

c) public int compare(Score s1,Score s2){/*more code here*/}

d) public int compare(Object o1,Object o2){/*more code here*/}

47) 3. public class Batman {

int squares = 81;

public static void main(String[] args) {

new Batman().go();

}

void go() {

incr(++squares);

System.out.println(squares);

}

void incr(int squares) { squares += 10; }

}程序运行结果是( )

a) 81

b) 82

c) 91

d) 92

48) 15. public class Yippee {

public static void main(String [] args) {

for(int x = 1; x < args.length; x++) {

System.out.print(args[x] + " "); 19. } 20. } 21. }

在控制台依次输入两条命令

java Yippee

java Yippee 1 2 3 4

程序的运行结果是( )

a) No output is produced. 1 2 3

b) No output is produced. 2 3 4

c) No output is produced. 1 2 3 4

d) An exception is thrown at runtime. 1 2 3

e) An exception is thrown at runtime. 2 3 4

f) An exception is thrown at runtime. 1 2 3 4

49) 13. public class Pass {

public static void main(String [] args) {

int x = 5;

Pass p = new Pass();

p.doStuff(x);

System.out.print(" main x = " + x);

}

21. void doStuff(int x) {

System.out.print(" doStuff x = " + x++);

}

}程序的运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) doStuff x = 6 main x = 6

d) doStuff x = 5 main x = 5

e) doStuff x = 5 main x = 6

f) doStuff x = 6 main x = 5

50) 3. interface Animal { void makeNoise(); }

class Horse implements Animal {

Long weight = 1200L;

public void makeNoise() { System.out.println("whinny"); }

}

public class Icelandic extends Horse {

public void makeNoise() { System.out.println("vinny"); }

public static void main(String[] args) {

Icelandic i1 = new Icelandic(); Icelandic i2 = new Icelandic();

12. Icelandic i3 = new Icelandic();

i3 = i1; i1 = i2; i2 = null; i3 = i1;

}

}程序运行结束后,有几个对象符合垃圾回收的条件( )

a) 0

b) 1

c) 2

d) 3

e) 4

f) 6

51) 11. String[] elements = { "for", "tea", "too" };

String first = (elements.length > 0) elements[0] : null;

程序运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) The variable first is set to null.

d) The variable first is set to elements[0].

52) 31. class Foo {

public int a = 3;

public void addFive() { a += 5; System.out.print(“f “); }

}

class Bar extends Foo {

public int a = 8;

public void addFive() { this.a += 5; System.out.print(“b ” ); }

}

主方法执行下列语句

Foo f = new Bar();

f.addFive();

System.out.println(f.a); 程序运行结果是()

a) b,3

b) b,8

c) b,13

d) f,3

e) f,8

f) f,13

g) Compilation fails.

h) An exception is thrown at runtime.

53) 1. class ClassA {

public int numberOfInstances;

protected ClassA(int numberOfInstances) {

this.numberOfInstances = numberOfInstances;

}

}

public class ExtendedA extends ClassA {

private ExtendedA(int numberOfInstances) {

uper(numberOfInstances);

}

public static void main(String[] args) {

ExtendedA ext = new ExtendedA(420);

System.out.print(ext.numberOfInstances);

}

} 下列哪句描述是正确的()

a) 420 is the output.

b) An exception is thrown at runtime.

c) All constructors must be declared public

d) Constructors CANNOT use the private modifier.

e) Constructors CANNOT use the protected modifier.

54) 11. class ClassA {}

class ClassB extends ClassA {}

class ClassC extends ClassA {}

and:

ClassA p0 = new ClassA();

ClassB p1 = new ClassB();

ClassC p2 = new ClassC();

ClassA p3 = new ClassB();

ClassA p4 = new ClassC();

下边哪句代码是正确的,请选择3个( )

a) p0 = p1;

b) p1 = p2;

c) p2 = p4;

d) p2 = (ClassC)p1;

e) p1 = (ClassB)p3;

f) p2 = (ClassC)p4;

55) 5. class Thingy { Meter m = new Meter(); }

class Component { void go() { System.out.print(“c”); } }

class Meter extends Component { void go() { System.out.print(“m”); } }

9. class DeluxeThingy extends Thingy {

public static void main(String[] args) {

DeluxeThingy dt = new DeluxeThingy();

dt.m.go();

Thingy t = new DeluxeThingy();

t.m.go();

}

}下边哪句描述是正确的,请选择2个( )

a) The output is mm.

b) The output is mc.

c) Component is-a Meter.

d) Component has-a Meter.

e) DeluxeThingy is-a Component.

f) DeluxeThingy has-a Component.

56) 10. interface Jumper { public void jump(); } …

class Animal {} …

class Dog extends Animal {

Tail tail;

} …

class Beagle extends Dog implements Jumper{

public void jump() {}

} …

class Cat implements Jumper{

public void jump() {}

}下边哪句描述是正确的,请选择3个( )

a) Cat is-a Animal

b) Cat is-a Jumper

c) Dog is-a Animal

d) Dog is-a Jumper

e) Cat has-a Animal

f) Beagle has-a Tail

g) Beagle has-a Jumper

57) 1. import java.util.*;

public class WrappedString {

private String s;

public WrappedString(String s) { this.s = s; }

public static void main(String[] args) {

HashSeths = new HashSet();

WrappedString ws1 = new WrappedString(“aardvark”);

WrappedString ws2 = new WrappedString(“aardvark”);

String s1 = new String(“aardvark”);

String s2 = new String(“aardvark”);

hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);

System.out.println(hs.size()); } }运行结果是( )

a) 0

b) 1

c) 2

d) 3

e) 4

f) Compilation fails.

d) An exception is thrown at runtime.

58) 2. import java.util.*;

public class GetInLine {

public static void main(String[] args) {

PriorityQueue pq = new PriorityQueue();

pq.add(“banana”);

pq.add(“pear”);

pq.add(“apple”);

System.out.println(pq.poll() + ” ” + pq.peek());

}

}

运行结果是( )

a) apple pear

b) banana pear

c) apple apple

d) apple banana

59) 3. import java.util.*;

public class Mapit {

public static void main(String[] args) {

Set set = new HashSet();

Integer i1 = 45;

Integer i2 = 46;

set.add(i1);

set.add(i1);

set.add(i2); System.out.print(set.size() + ” “);

set.remove(i1); System.out.print(set.size() + ” “);

i2 = 47;

set.remove(i2); System.out.print(set.size() + ” “);

} 16. }程序运行结果是( )

a) 2 1 0

b) 2 1 1

c) 3 2 1

d) 3 2 2

60) 12. import java.util.*;

public class Explorer1 {

public static void main(String[] args) {

TreeSet s = new TreeSet();

TreeSet subs = new TreeSet();

for(int i = 606; i < 613; i++)

if(i%2 == 0) s.add(i);

subs = (TreeSet)s.subSet(608, true, 611, true);

. s.add(609);

System.out.println(s + " " + subs);

} 23. }运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) [608, 609, 610, 612] [608, 610]

d) [608, 609, 610, 612] [608, 609, 610]

e) [606, 608, 609, 610, 612] [608, 610]

f) [606, 608, 609, 610, 612] [608, 609, 610]

61) 3. import java.util.*;

public class Quest {

public static void main(String[] args) {

String[] colors = {"blue", "red", "green", "yellow", "orange"};

Arrays.sort(colors);

int s2 = Arrays.binarySearch(colors, "orange");

int s3 = Arrays.binarySearch(colors, "violet");

System.out.println(s2 + " " + s3);

} 12. }运行结果是( )

a) 2 -1

b) 2 -4

c) 2 -5

d) 3 -1

e) 3 -4

f) 3 -5

g) Compilation fails.

h) An exception is thrown at runtime

62) 34. HashMap props = new HashMap();

props.put("key45", "some value");

props.put("key12", "some other value");

props.put("key39", "yet another value");

. Set s = props.keySet();

// insert code here

下列哪行代码放到39行是正确的( )

a) Arrays.sort(s);

b) s = new TreeSet(s);

c) Collections.sort(s);

d) s = new SortedSet(s);

63) 1. public class TestOne implements Runnable {

public static void main (String[] args) throws Exception {

Thread t = new Thread(new TestOne());

t.start();

System.out.print("Started");

t.join();

System.out.print("Complete");

}

public void run() {

for (int i = 0; i < 4; i++) {

System.out.print(i);

} 13. } 14. }语系那个结果是()

a) Compilation fails.

b) An exception is thrown at runtime.

c) The code executes and prints "StartedComplete".

d) The code executes and prints "StartedComplete0123"

e) The code executes and prints "Started0123Complete".

64) 下边哪行代码是正确的,请选择3个( )

a) private synchronized Object o;

b) void go() { synchronized() { /* code here */ }

c) public synchronized void go() { /* code here */ }

d) private synchronized(this) void go() { /* code here */ }

e) void go() { synchronized(Object.class) { /* code here */ }

f) void go() { Object o = new Object(); synchronized(o) { /* code here */ }

65) 1. public class TestFive {

private int x;

public void foo() {

int current = x;

. x = current + 1;

}

public void go() {

for(int i = 0; i < 5; i++) {

new Thread() {

public void run() {

foo();

System.out.print(x + ", ");

} }.start();

} }程序如何修改,可以保证输出1,2,3,4,5,选择2个( )

a) move the line 12 print statement into the foo() method

b) change line 7 to public synchronized void go() {

c) change the variable declaration on line 2 to private volatile int x;

d) wrap the code inside the foo() method with a synchronized( this ) block

e) wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }

66) 11. Runnable r = new Runnable() {

public void run() {

System.out.print("Cat");

}

};

Thread t = new Thread(r) {

public void run() {

System.out.print("Dog");

}

};

t.start(); 程序运行结果是( )

a) Cat

b) Dog

c) Compilation fails.

d) The code runs with no output.

67) 1. public class Threads5 {

public static void main (String[] args) {

new Thread(new Runnable() {

public void run() {

System.out.print("bar");

}}).start();

} 8. }程序运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) The code executes normally and prints "bar".

d) The code executes normally, but nothing prints.

68) 10. class One {

void foo() { }

. }

class Two extends One {

//insert method here

}下列哪个方法放到第14行,程序可以编译正常,请选择3个( )

a) nt foo() { /* more code here */ }

b) void foo() { /* more code here */ }

c) public void foo() { /* more code here */ }

d) private void foo() { /* more code here */ }

e) protected void foo() { /* more code here */ }

69) 10. abstract public class Employee {

protected abstract double getSalesAmount();

public double getCommision() {

return getSalesAmount() * 0.15;

} 15. }

class Sales extends Employee {

// insert method here

}下列哪个方法放到第17行,程序可以编译正常,请选择2个( )

a) double getSalesAmount() { return 1230.45; }

b) public double getSalesAmount() { return 1230.45; }

c) private double getSalesAmount() { return 1230.45; }

d) protected double getSalesAmount() { return 1230.45; }

70) 1. class X {

X() { System.out.print(1); }

X(int x) {

this(); System.out.print(2);

} 6. }

public class Y extends X {

Y() { super(6); System.out.print(3); }

Y(int y) {

this(); System.out.println(4); 11. }

. public static void main(String[] a) { new Y(5); }

}程序运行结果是( )

a) 13

b) 134

c) 1234

d) 2134

e) 2143

f) 4321

71) 10. package com.sun.scjp;

public class Geodetics {

public static final double DIAMETER = 12756.32; // kilometers

}哪两行代码可以正确的访问变量DIAMETER,选择2个( )

a) import com.sun.scjp.Geodetics;

public class TerraCarta { public double halfway() { return Geodetics.DIAMETER/2.0; }

b) import static com.sun.scjp.Geodetics;

public class TerraCarta{ public double halfway() { return DIAMETER/2.0; } }

c) import static com.sun.scjp.Geodetics.*;

public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }

d) package com.sun.scjp;

public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }

72) 1. public class A {

public void doit() {

}

public String doit() {

return "a";

}

public double doit(int x) {

return 1.0;

} 10. }运行结果是( )

a) An exception is thrown at runtime.

b) Compilation fails because of an error in line 7.

c) Compilation fails because of an error in line 4.

d) Compilation succeeds and no runtime errors with class A occur.

73) 35. String #name = "Jane Doe";

int $age = 24;

Double _height = 123.5;

double ~temp = 37.5; 哪行代码是正确的,选择2个( )

a) 35

b) 36

c) 37

d) 38

74) 10. interface Foo { int bar(); }

public class Sprite {

public int fubar( Foo foo ) { return foo.bar(); }

public void testFoo() {

fubar( // insert code here );

} 16. }下边哪行代码是正确的( )

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; }

75) 11. public enum Title {

MR("Mr."), MRS("Mrs."), MS("Ms.");

private final String title;

private Title(String t) { title = t; }

public String format(String last, String first) {

return title + " " + first + " " + last; 17. } 18. }

public static void main(String[] args) {

System.out.println(Title.MR.format("Doe", "John")); 21. }

运行结果是( )

a) Mr. John Doe

b) An exception is thrown at runtime.

c) Compilation fails because of an error in line 12

d) Compilation fails because of an error in line 15.

) 10. class Line {

public static class Point {}

}

class Triangle {

// insert code here

}要创建一个point的对象,下面那句是正确的( )

a) Point p = new Point();

b) Line.Point p = new Line.Point();

c) The Point class cannot be instatiated at line 15.

d) Line l = new Line() ; l.Point p = new l.Point();

77) 接口里的变量默认是什么类型的,选择3个( )

a) final

b) static

c) private

d) public

e) protected

f) native

78) 1. package util;

public class BitUtils {

public static void process(byte[] b) { /* more code here */ }

}

package app;

. public class SomeApp {

public static void main(String[] args) {

byte[] bytes = new byte[256];

// insert code here

} 7. }在第五行调用process方法,下边哪句代码是正确的( )

a) process(bytes);

b) BitUtils.process(bytes);

c) util.BitUtils.process(bytes);

d) import util.BitUtils.*; process(bytes);

79) class Inner {

private int x;

public void setX(int x){

this.x = x;

}

public int getX(){

return x;

}

}

class Outer{

private Inner y;

public void setY(Inner y){

this.y = y;

}

public Inner getY(){

return y;

}

}

public class Gamma{

public static void main(String[] args){

Outer o = new Outer();

Inner i = new Inner();

int n = 10;

i.setX(n);

o.setY(i);

//insert code here

System.out.println(o.getY().getX());

}

}下边哪行代码放到注释的地方,可以保证程序输出结果为100,

选择3个( )

a) n = 100;

b) i.setX( 100 );

c) o.getY().setX( 100 );

d) i = new Inner(); i.setX( 100 );

e) o.setY( i ); i = new Inner(); i.setX( 100 );

f) i = new Inner(); i.setX( 100 ); o.setY( i );

80) 11. class Snoochy {

Boochy booch;

public Snoochy() { booch = new Boochy(this); }

}

class Boochy {

Snoochy snooch;

public Boochy(Snoochy s) { snooch = s; }

} And the statements:

public static void main(String[] args) {

Snoochy snoog = new Snoochy();

snoog = null;

.// more code here

}23行执行完之后,下边哪句话是正确的( )

a) None of these objects are eligible for garbage collection.

b) Only the object referenced by booch is eligible for garbage collection.

c) Only the object referenced by snooch is eligible for garbage collection.

d) The objects referenced by snooch and booch are eligible for garbage collection.

81) 5. class Payload {

private int weight;

public Payload (int w) { weight = w; }

public void setWeight(int w) { weight = w; }

public String toString() { return Integer.toString(weight); }

}

public class TestPayload {

static void changePayload(Payload p) { /* insert code */ }

public static void main(String[] args) {

Payload p = new Payload(200);

p.setWeight(1024);

changePayload(p);

System.out.println("p is " + p);

} }下边那句代码插入到第12行,可以保证程序输出结果是420( )

a) p.setWeight(420);

b) p.changePayload(420);

c) p = new Payload(420);

d) Payload.setWeight(420);

82) 11. public static void test(String str) {

int check = 4;

if (check = str.length()) {

System.out.print(str.charAt(check -= 1) +", ");

} else {

System.out.print(str.charAt(0) + ", ");

} 18. } and the invocation:

test("four");

test("tee");

test("to"); 运行结果是什么( )

a) r, t, t,

b) r, e, o,

c) Compilation fails.

d) An exception is thrown at runtime.

83) 1. package util;

public class BitUtils {

private static void process(byte[] b) {}

}

package app;

public class SomeApp {

public static void main(String[] args) {

byte[] bytes = new byte[256];

// insert code here

} 7. } 在第五行正确调用process方法的代码是( )

a) process(bytes);

b) BitUtils.process(bytes);

c) util.BitUtils.process(bytes);

d) SomeApp cannot use the process method in BitUtils.

e) import util.BitUtils.*; process(bytes);

f) app.BitUtils.process(bytes);

84) 15. public class Pass2 {

public void main(String [] args) {

int x = 6;

Pass2 p = new Pass2();

p.doStuff(x);

System.out.print(" main x = " + x);

}

void doStuff(int x) {

System.out.print(" doStuff x = " + x++);

}

}在控制台依次输入命令

javac Pass2.java

java Pass2 5 运行结果是()

a) Compilation fails.

b) An exception is thrown at runtime.

c) doStuff x = 6 main x = 6

d) doStuff x = 6 main x = 7

e) doStuff x = 7 main x = 6

f) doStuff x = 7 main x = 7

85) 12. public class Test {

public enum Dogs {collie, harrier};

public static void main(String [] args) {

Dogs myDog = Dogs.collie;

switch (myDog) {

case collie:

System.out.print("collie ");

case harrier:

System.out.print("harrier ");

} 22. } 23. } 运行结果是( )

a) collie

b) harrier

c) Compilation fails

d) collie harrier

e) An exception is thrown at runtime.

86) 1. public class Donkey {

public static void main(String[] args) {

boolean assertsOn = false;

assert (assertsOn) : assertsOn = true;

if(assertsOn) {

System.out.println("assert is on");

7} 8. } 9. } 运行结果是( )

a) no output

b) no output assert is on

c) assert is on

d) no output An AssertionError is thrown.

e) assert is on An AssertionError is thrown.

87) 11. static void test() {

try {

String x = null;

System.out.print(x.toString() + " ");

}

finally { System.out.print("finally "); }

}

public static void main(String[] args) {

try { test(); }

. catch (Exception ex) { System.out.print("exception "); }

} 运行结果是( )

a) null

b) finally

c) Null finally

d) Compilation fails.

e) finally exception

88) 11. static void test() throws Error {

if (true) throw new AssertionError();

System.out.print("test ");

}

public static void main(String[] args) {

try { test(); }

catch (Exception ex) { System.out.print("exception "); }

. System.out.print("end ");

}运行结果是( )

a) end

b) Compilation fails.

c) exception test end

d) exception end

e) A Throwable is thrown by main.

f) An Exception is thrown by main

89) 1. class TestException extends Exception { }

class A {

public String sayHello(String name) throws TestException {

if(name == null) throw new TestException();

return "Hello " + name;

} 7. }

public class TestA {

public static void main(String[] args) {

new A().sayHello("Aiko");

} 12. }运行结果是( )

a) Compilation succeeds.

b) Class A does not compile.

c) The method declared on line 9 cannot be modified to throw TestException.

d) TestA compiles if line 10 is enclosed in a try/catch block that catches TestException.

90) 11. public static Collection get() {

Collection sorted = new LinkedList();

sorted.add("B"); sorted.add("C"); sorted.add("A");

return sorted;

} 16. public static void main(String[] args) {

for (Object obj: get()) {

System.out.print(obj + ", ");

} 20. }运行结果是( )

a) A, B, C,

b) B, C, A,

c) Compilation fails.

d) The code runs with no output.

e) An exception is thrown at runtime.

91) 11. static class A {

. void process() throws Exception { throw new Exception(); }

}

. static class B extends A {

void process() { System.out.println("B"); }

}

public static void main(String[] args) {

new B().process(); 19. } 运行结果是( )

a) B

b) The code runs with no output.

c) Compilation fails because of an error in line 12.

d) Compilation fails because of an error in line 15.

92) 10. public class Foo {

static int[] a;

static { a[0]=2; }

public static void main( String[] args ) {}

} 运行这段代码时会出现什么错误( )

a) java.lang.StackOverflowError

b) java.lang.IllegalStateException

c) java.lang.ExceptionInInitializerError

d) java.lang.ArrayIndexOutOfBoundsException

93) 11. public static void main(String[] args) {

Integer i = new Integer(1) + new Integer(2);

switch(i) {

case 3: System.out.println("three"); break;

default: System.out.println("other"); break;

} 17. } 运行结果是( )

a) three

b) other

c) An exception is thrown at runtime.

d) Compilation fails because of an error on line 12.

e) Compilation fails because of an error on line 13.

f) Compilation fails because of an error on line 15.

94) 11. public static Iterator reverse(List list) {

Collections.reverse(list);

return list.iterator();

}

public static void main(String[] args) {

List list = new ArrayList();

list.add("1"); list.add("2"); list.add("3");

for (Object obj: reverse(list))

System.out.print(obj + ", ");

} 运行结果是( )

a) 3,2,1

b) 1,2,3

c) Compilation fails.

d) The code runs with no output.

95) 1. public class TestString3 {

public static void main(String[] args) {

// insert code here

System.out.println(s);

}

} 下边哪两段代码放在第三行,可以保证程序输出4247( )

a) String s = "123456789"; s = (s-"123").replace(1,3,"24") - "89";

b) StringBuffer s =

new StringBuffer("123456789");

s.delete(0,3).replace(1,3,"24").delete(4,6);

c) StringBuffer s = new StringBuffer("123456789");

s.substring(3,6).delete(1,3).insert(1, "24");

d) StringBuilder s = new StringBuilder("123456789");

s.substring(3,6).delete(1,2).insert(1,"24");

e) StringBuilder s =

new StringBuilder("123456789");

s.delete(0,3).delete(1,3).delete(2,5).insert(1, "24");

96) 5. import java.util.Date;

import java.text.DateFormat;

DateFormat df;

Date date = new Date();

// insert code here

String s = df.format(date);

哪段代码放到23行,程序可以正确编译( )

a) df = new DateFormat();

b) df = Date.getFormat();

c) df = date.getFormat();

d) df = DateFormat.getFormat();

e) df = DateFormat.getInstance();

97) 1. public class BuildStuff {

public static void main(String[] args) {

Boolean test = new Boolean(true);

Integer x = 343;

Integer y = new BuildStuff().go(test, x);

System.out.println(y);

}

int go(Boolean b, int i) {

if(b) return (i/7);

return (i/49);

} 12. } 运行结果是( )

a) 7

b) 49

c) 343

d) Compilation fails.

98) 12. import java.io.*;

public class Forest implements Serializable {

private Tree tree = new Tree();

public static void main(String [] args) {

Forest f = new Forest();

try {

FileOutputStream fs = new FileOutputStream("Forest.ser");

ObjectOutputStream os = new ObjectOutputStream(fs);

os.writeObject(f); os.close();

} catch (Exception ex) { ex.printStackTrace(); }

} }

class Tree { } 运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) An instance of Forest is serialized.

d) An instance of Forest and an instance of Tree are both serialized.

99) 5. import java.io.*;

public class Talk {

public static void main(String[] args) {

Console c = new Console();

String pw;

System.out.print("password: ");

pw = c.readLine();

System.out.println("got " + pw);

} 14. } 运行结果是( )

a) password: got

b) password: got aiko

c) password: aiko got aiko

d) An exception is thrown at runtime.

e) Compilation fails due to an error on line 8.

100) 11. String test = "Test A. Test B. Test C.";

// insert code here

String[] result = test.split(regex);

下列哪行代码放到第12行,可以正确编译( )

a) String regex = "";

b) String regex = " ";

c) String regex = ".*";

d) String regex = "\\s";

e) String regex = "\\.\\s*";

f) String regex = "\\w[ \.] +";

101) 1. interface A { public void aMethod(); }

interface B { public void bMethod(); }

interface C extends A,B { public void cMethod(); }

class D implements B {

public void bMethod(){}

}

class E extends D implements C {

public void aMethod(){}

public void bMethod(){}

public void cMethod(){} 11. } 下列那句话是正确的( )

a) Compilation fails because of an error in line 3.

b) Compilation fails because of an error in line 7.

c) Compilation fails because of an error in line 9.

d) If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.

e) .If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.

f) If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

102) public class SimpleCalc{

public int value;

public void calculate(){

value += 7;

}

}

and

public class MultiCalc extends SimpleCale{

public void calculate(){

value -= 3;

}

public void calculate(int multiplier){

calculate();

super.calculate();

value *= multiplier;

}

public static void main(String[] args){

MultiCalc calculator = new MultiCalc();

calculator.calculate(2);

System.out.println("Value is: " + calculator.value);

}

}运行结果是( )

a) Value is: 8

b) Compilation fails.

c) Value is: 12

d) Value is: -12

e) The code runs with no output.

f) An exception is thrown at runtime.

103) 1. 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

e) barbarbarbarbar

f) foofoofoobarbar

g) foofoofoobarfoo

104) 11. class Mammal { }

. class Raccoon extends Mammal {

Mammal m = new Mammal();

}

class BabyRaccoon extends Mammal { }

下列哪句说法是正确的,选择4个( )

a) Raccoon is-a Mammal.

b) Raccoon has-a Mammal.

c) BabyRaccoon is-a Mammal.

d) BabyRaccoon is-a Raccoon.

e) BabyRaccoon has-a Mammal.

f) BabyRaccoon is-a BabyRaccoon.

105) 10. interface A { void x(); }

class B implements A { public void x() {} public void y() {} }

class C extends B { public void x() {} } And: java.util.List list = new java.util.ArrayList();

list.add(new B());

list.add(new C());

for (A a : list) {

a.x();

a.y();

} 运行结果是( )

a) The code runs with no output.

b) An exception is thrown at runtime.

c) Compilation fails because of an error in line 20.

d) Compilation fails because of an error in line 21.

e) Compilation fails because of an error in line 23.

f) Compilation fails because of an error in line 25.

106) 2. public class Hi {

void m1() { }

protected void() m2 { }

} 6. class Lois extends Hi {

// insert code here

} 下列哪句代码放到第7行,可以正确编译,选4个( )

a) public void m1() { }

b) protected void m1() { }

c) private void m1() { }

d) void m2() { }

e) public void m2() { }

f) protected void m2() { }

g) private void m2() { }

107) 10: public class Hello {

String title; int value;

public Hello() {

title += " World";

}

public Hello(int value) {

this.value = value;

title = "Hello";

Hello();

} 21: } and:

Hello c = new Hello(5);

System.out.println(c.title); 运行结果是( )

a) Hello

b) Hello World

c) Compilation fails.

d) The code runs with no output

108) 10. interface Data { public void load(); }

abstract class Info { public abstract void load(); }

下列哪段代码是正确的( )

a) public class Employee extends Info implements Data { public void load() { /*do something*/ } }

b) public class Employee implements Info extends Data { public void load() { /*do something*/ } }

c) public class Employee extends Info implements Data public void load(){ /*do something*/ } public void Info.load(){ /*do something*/ } }

d) public class Employee implements Info extends Data { public void Data.load(){ /*do something*/ } public void load(){ /*do something*/ } }

109) 1. class Alligator {

public static void main(String[] args) {

int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

int [][]y = x;

System.out.println(y[2][1]); 6. } 7. } 运行结果是( )

a) 2

b) 3

c) 4

d) 6

e) 7

f) Compilation fails

110) 21. abstract class C1 {

public C1() { System.out.print(1); }

}

class C2 extends C1 {

public C2() { System.out.print(2); } 26. }

class C3 extends C2 {

public C3() { System.out.println(3); } 29. }

public class Ctest {

public static void main(String[] a) { new C3(); } 32. }

运行结果是( )

a) 3

b) 23

c) 32

d) 123

e) 321

f) Compilation fails.

111) 10. class One {

public One foo() { return this; } 12. }

class Two extends One {

public One foo() { return this; } 15. }

class Three extends Two {

// insert method here 18. }

哪2行代码放到第17行,程序可以正确编译()

a) public void foo() {}

b) public int foo() { return 3; }

c) public Two foo() { return this; }

d) public One foo() { return this; }

e) public Object foo() { return this; }

112) 下边哪两个类正确实现了 java.lang.Runnable 和 java.lang. Cloneable 接口

( )

a) public class Session implements Runnable, Cloneable { public void run(); public Object clone(); }

b) public class Session extends Runnable, Cloneable { public void run() { /* do something */ } public Object clone() { /* make a copy */ }

c) public class Session implements Runnable, Cloneable { public void run() { /* do something */ } public Object clone() { /* make a copy */ }

d) public abstract class Session implements Runnable, Cloneable { public void run() { /* do something */ } public Object clone() { /*make a copy */ }

e) public class Session implements Runnable, implements Cloneable { public void run() { /* do something */ } public Object clone() { /* make a copy */ }

113) 11. public interface A { public void m1(); } 12.

class B implements A { }

class C implements A { public void m1() { } }

class D implements A { public void m1(int x) { } }

abstract class E implements A { }

abstract class F implements A { public void m1() { } }

abstract class G implements A { public void m1(int x) { } }

下列哪句描述是正确的( )

a) Compilation succeeds.

b) Exactly one class does NOT compile.

c) Exactly two classes do NOT compile.

d) Exactly four classes do NOT compile.

114) 10. class Line {

public class Point { public int x,y;}

public Point getPoint() { return new Point(); } 13. }

class Triangle {

public Triangle() {

// insert code here 17. } 18. }

下列哪句代码放到16行是正确的( )

a) Point p = Line.getPoint();

b) Line.Point p = Line.getPoint();

c) Point p = (new Line()).getPoint();

d) Line.Point p = (new Line()).getPoint();

115) 1. class TestA {

public void start() { System.out.println("TestA"); } 3. }

public class TestB extends TestA {

public void start() { System.out.println("TestB"); }

public static void main(String[] args) {

((TestA)new TestB()).start(); 8. } 9. }

运行结果是( )

a) TestA

b) TestB

c) Compilation fails

d) An exception is thrown at runtime

116) public interface A{

public oid doSomething(String thing);

}

public class AImpl implements A{

public void doSomething(String thing){}

}

public class B{

public A doit(){

//more code here

}

public String execute(){

//more code here

}

}

pulblic class C extends B{

public AImpl doit(){

//more code here

}

public Object execute(){

//more code here

}

} 运行结果是( )

a) Compilation will succeed for all classes and interfaces.

b) Compilation of class C will fail because of an error in line 2.

c) Compilation of class C will fail because of an error in line 6.

d) Compilation of class AImpl will fail because of an error in line 2.

117) 11. public static void main(String[] args) {

Object obj = new int[] { 1, 2, 3 };

int[] someArray = (int[])obj;

for (int i : someArray) System.out.print(i + " "); } 运行结果是( )

a) 1 2 3

b) Compilation fails because of an error in line 12.

c) Compilation fails because of an error in line 13.

d) Compilation fails because of an error in line 14

118) public class Threads1{

int x = 0;

public class Runner implements Runnable{

public void run(){

int current = 0;

for(int i=0;i<4;i++){

current = x;

System.out.println(current + ",");

x = current + 2;

}

}

}

public static void main(String[] args){

new Threads1().go();

}

public void go(){

Runnable rl = new Runner();

new Thread(rl).start();

new Thread(rl).start();

}

} 运行结果是,选择2个( )

a) 0, 2, 4, 4, 6, 8, 10, 6,

b) 0, 2, 4, 6, 8, 10, 2, 4,

c) 0, 2, 4, 6, 8, 10, 12, 14,

d) 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,

e) 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

119) 1. public class TestOne implements Runnable {

public static void main (String[] args) throws Exception {

Thread t = new Thread(new TestOne());

t.start();

System.out.print("Started");

t.join();

System.out.print("Complete"); 8. }

public void run() {

for (int i = 0; i < 4; i++) {

System.out.print(i); 12. } 13. } 14. } 运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) The code executes and prints "StartedComplete".

d) The code executes and prints "StartedComplete0123".

e) The code executes and prints "Started0123Complete".

120) public class Starter extends Thread{

private int x = 2;

public static void main(String[] args)throws Exception{

new Starter().makeItSo();

}

public Starter(){

x = 5;

start();

}

public void makeItSo() throws Exception{

join();

x = x - 1;

System.out.println(x);

}

public void run(){x *= 2;}

} 运行结果是( ) 题库170

a) 4

b) 5

c) 8

d) 9

e) Compilation fails.

f) An exception is thrown at runtime.

g) It is impossible to determine for certain.

121) 11. public class PingPong implements Runnable {

synchronized void hit(long n) {

for(int i = 1; i < 3; i++)

System.out.print(n + "-" + i + " "); 15. }

public static void main(String[] args) {

new Thread(new PingPong()).start();

new Thread(new PingPong()).start(); 19. }

public void run() {

hit(Thread.currentThread().getId()); 22. } 23. }

下列哪种是可能的输出,选择2个( )

a) The output could be 8-1 7-2 8-2 7-1

b) The output could be 7-1 7-2 8-1 6-1

c) The output could be 8-1 7-1 7-2 8-2

d) The output could be 8-1 8-2 7-1 7-2

122) public class Computation extends Thread{

private int num;

private boolean isComplete;

private int result;

public Computation(int num){

this.num = num;

}

public synchronized void run(){

result = num * 2;

isComplete = true;

notify();

}

public synchronized int getResult(){

while(!isComplete){

try{

wait();

}catch(InterruptedException e){}

}

return result;

}

public static void main(String[] args){

Computation[] computations = new Computation[4];

for(int i=0;i

computations[i] = new Computation(i);

computations[i].start();

}

for(Computation c:computations){

System.out.print(c.getResult()+ "") ;

}

}

}运行结果是()

a) The code will deadlock.

b) The code may run with no output.

c) An exception is thrown at runtime.

d) The code may run with output "0 6".

e) The code may run with output "2 0 6 4".

f) The code may run with output "0 2 4 6".

123) 下列哪行代码可以再一个线程里正确的运行doStuff方法选择2个( )

a) new Thread() { public void run() { doStuff(); } };

b) new Thread() { public void start() { doStuff(); } };

c) new Thread() { public void start() { doStuff(); } }.run();

d) new Thread() { public void run() { doStuff(); } }.start();

e) new Thread(new Runnable() { public void run() { doStuff(); } }).run();

f) new Thread(new Runnable() { public void run() { doStuff(); } }).start();

124) 11. public class Person {

private String name;

public Person(String name) {

this.name = name; 15. }

public boolean equals(Object o) {

if ( ! ( o instanceof Person) ) return false;

Person p = (Person) o;

return p.name.equals(this.name); 20. } 21. }下边正确的描述是( )

a) Compilation fails because the hashCode method is not overridden.

b) A HashSet could contain multiple Person objects with the same name.

c) All Person objects will have the same hash code because the hashCode method is not overridden.

d) If a HashSet contains more than one Person object with name="Fred", then removing another Person, also with name="Fred", will remove them all.

125) 5. import java.util.*;

public class SortOf {

public static void main(String[] args) {

ArrayList a = new ArrayList();

a.add(1); a.add(5); a.add(3);

Collections.sort(a);

a.add(2);

Collections.reverse(a);

System.out.println(a); 15. } 16. }运行结果是( )

a) [1, 2, 3, 5]

b) [2, 1, 3, 5]

c) [2, 5, 3, 1]

d) [5, 3, 2, 1]

e) [1, 3, 5, 2]

f) Compilation fails.

g) An exception is thrown at runtime.

126) 11. public class Person {

private name;

public Person(String name) {

this.name = name; 15. }

public int hashCode() {

return 420; 18. } 19. }下列哪句描述是正确的( )

a) The time to find the value from HashMap with a Person key depends on the size of the map.

b) Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.

c) Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate.

d) The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.

127) 12. import java.util.*;

public class Explorer2 {

public static void main(String[] args) {

TreeSet s = new TreeSet();

TreeSet subs = new TreeSet();

for(int i = 606; i < 613; i++)

if(i%2 == 0) s.add(i);

subs = (TreeSet)s.subSet(608, true, 611, true);

s.add(629);

System.out.println(s + " " + subs); 22. } 23. }运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime.

c) [608, 610, 612, 629] [608, 610]

d) [608, 610, 612, 629] [608, 610, 629]

e) [606, 608, 610, 612, 629] [608, 610]

f) [606, 608, 610, 612, 629] [608, 610, 629]

128) 1. import java.util.*;

public class Example {

public static void main(String[] args) {

// insert code here

set.add(new Integer(2));

set.add(new Integer(1));

System.out.println(set); 8. } 9. }

下列哪句代码放到第4行,可以保证输出[1, 2]( )

a) Set set = new TreeSet();

b) Set set = new HashSet();

c) Set set = new SortedSet();

d) List set = new SortedList();

129) 5. class A {

void foo() throws Exception { throw new Exception(); } 7. }

class SubB2 extends A {

void foo() { System.out.println("B "); } 10. }

class Tester {

public static void main(String[] args) {

A a = new SubB2();

a.foo(); 15. } 16. } 运行结果是( )

a) B

b) B, followed by an Exception.

c) Compilation fails due to an error on line 9.

d) Compilation fails due to an error on line 14.

e) An Exception is thrown with no other output

130) 84. try {

ResourceConnection con = resourceFactory.getConnection();

Results r = con.query("GET INFO FROM CUSTOMER");

info = r.getData();

con.close();

} catch (ResourceException re) {

errorLog.write(re.getMessage()); 91. }

return info;

如果第86行抛出一个异常,下边哪句话是正确的( )

a) Line 92 will not execute.

b) The connection will not be retrieved in line 85.

c) The resource connection will not be closed on line 88.

d) The enclosing method will throw an exception to its caller.

131) 3. public class Breaker {

static String o = "";

public static void main(String[] args) {

z:

o = o + 2;

for(int x = 3; x < 8; x++) {

if(x==4) break;

if(x==6) break z;

o = o + x; 12. }

System.out.println(o); 14. } 15. }运行结果是( )

a) 23

b) 234

c) 235

d) 2345

e) 2357

f) 23457

g) Compilation fails.

132) 11. public void go(int x) {

assert (x > 0);

switch(x) {

case 2: ;

default: assert false; 16. } 17. }

private void go2(int x) { assert (x < 0); }下列哪句描述是正确的()

a) All of the assert statements are used appropriately.

b) Only the assert statement on line 12 is used appropriately.

c) Only the assert statement on line 15 is used appropriately.

d) Only the assert statement on line 18 is used appropriately.

e) Only the assert statements on lines 12 and 15 are used appropriately.

f) Only the assert statements on lines 12 and 18 are used appropriately.

g) Only the assert statements on lines 15 and 18 are used appropriately

133) 11. public static void main(String[] args) {

try {

args = null;

args[0] = "test";

System.out.println(args[0]);

} catch (Exception ex) {

System.out.println("Exception");

} catch (NullPointerException npe) {

System.out.println("NullPointerException"); 20. } 21. }运行结果是( )

a) test

b) Exception

c) Compilation fails.

d) NullPointerException

134) 11. public static void main(String[] args) {

for (int i = 0; i <= 10; i++) {

if (i > 6) break; 14. }

System.out.println(i); 16. }运行结果是( )

a) 6

b) Compilation fails.

c) 10

d) 11

135) 11. class X { public void foo() { System.out.print(“X “); } } 12.

public class SubB extends X {

public void foo() throws RuntimeException {

super.foo();

if (true) throw new RuntimeException();

System.out.print(“B “); 18. }

public static void main(String[] args) {

new SubB().foo(); 21. } 22. }运行结果是( )

a) X, followed by an Exception.

b) No output, and an Exception is thrown.

c) Compilation fails due to an error on line 14.

d) Compilation fails due to an error on line 16.

e) Compilation fails due to an error on line 17.

f) X, followed by an Exception, followed by B.

136)

11. public void testIfA() {

if (testIfB(“True”)) {

System.out.println(“True”);

} else {

System.out.println(“Not true”); 16. } 17. }

public Boolean testIfB(String str) {

return Boolean.valueOf(str); 20. }当testIfA方法被调用时结果是( )

a) True

b) Not true

c) An exception is thrown at runtime.

d) Compilation fails because of an error at line 12.

137) 下边哪两行代码会导致StackOverflowError,选择2个( )

a) int []x = {1,2,3,4,5}; for(int y = 0; y < 6; y++) System.out.println(x[y]);

b) static int[] x = {7,6,5,4}; static { x[1] = 8; x[4] = 3; }

c) or(int y = 10; y < 10; y++) doStuff(y);

d) void doOne(int x) { doTwo(x); } void doTwo(int y) { doThree(y); } void doThree(int z) { doTwo(z); }

e) for(int x = 0; x < 1000000000; x++) doStuff(x);

f) void counter(int i) { counter(++i); }

138) 5. public class Tahiti {

Tahiti t;

public static void main(String[] args) {

Tahiti t = new Tahiti();

Tahiti t2 = t.go(t);

. t2 = null;

// more code here 12. }

Tahiti go(Tahiti t) {

Tahiti t1 = new Tahiti(); Tahiti t2 = new Tahiti();

t1.t = t2; t2.t = t1; t.t = t2;

return t1; 17. } 18. }

程序执行完第11行后,有几个对象符合垃圾回收条件( )

a) 0

b) 1

c) 2

d) 3

e) Compilation fails.

139) 11. public class ItemTest {

. private final int id;

public ItemTest(int id) { this.id = id; }

public void updateId(int newId) { id = newId; } 15.

public static void main(String[] args) {

ItemTest fa = new ItemTest(42);

fa.updateId(69);

System.out.println(fa.id); 20. } 21. }运行结果是( )

a) Compilation fails.

b) An exception is thrown at runtime

c) The attribute id in the ItemTest object remains unchanged.

d) The attribute id in the ItemTest object is modified to the new value.

e) A new ItemTest object is created with the preferred value in the id attribute.

140) class Foo{

private int x;

public Foo(int x){

this.x = x;

}

public void setX(int x){

this.x = x;

}

public int getX(){ return x;}

}

public class Gamma{

static Foo fooBar(Foo foo){

foo = new Foo(100);

return foo;

}

public static void main(String[] args){

Foo foo = new Foo(300);

System.out.print(foo.getX() + “-”);

Foo fooFoo = fooBar(foo);

System.out.print(foo.getX() + “-”);

System.out.print(fooFoo.getX() + “-”);

foo = fooBar(fooFoo);

System.out.print(foo.getX() + “-”);

System.out.print(fooFoo.getX());

}

}运行结果是( )

a) 300-100-100-100-100

b) 300-300-100-100-100

c) 300-300-300-100-100

d) 300-300-300-100-100-100-100300-300-100

141) 1. package packageA;

public class Message {

String getText() { return “text”; }

} And:

package packageB;

public class XMLMessage extends packageA.Message {

String getText() { return “text”;}

public static void main(String[] args) {

System.out.println(new XMLMessage().getText()); 6. } 7. }

当运行类XMLMessage里的主方法时,结果是( )

a) text

b) Compilation fails.

c) text

d) An exception is thrown at runtime.

142) 3. interface Fish { }

class Perch implements Fish { }

class Walleye extends Perch { }

class Bluegill { }

public class Fisherman {

public static void main(String[] args) {

Fish f = new Walleye();

Walleye w = new Walleye();

Bluegill b = new Bluegill();

if(f instanceof Perch) System.out.print(“f-p “);

if(w instanceof Fish) System.out.print(“w-f “);

if(b instanceof Fish) System.out.print(“b-f “); 15. } 16. }运行结果是( )

a) w-f

b) f-p w-f

c) w-f b-f

d) f-p w-f b-f

e) Compilation fails.

143) 1. interface DoStuff2 {

float getRange(int low, int high); } 3.

interface DoMore {

float getAvg(int a, int b, int c); } 6.

abstract class DoAbstract implements DoStuff2, DoMore { } 8.

class DoStuff implements DoStuff2 {

public float getRange(int x, int y) { return 3.14f; } } 11.

interface DoAll extends DoMore {

float getAvg(int a, int b, int c, int d); }下边哪句描述是正确的( )

a) The file will compile without error.

b) Compilation fails. Only line 7 contains an error.

c) Compilation fails. Only line 12 contains an error.

d) Compilation fails. Only line 13 contains an error.

144) 1. import java.io.*;

public class Maker {

public static void main(String[] args) {

File dir = new File(“dir”);

File f = new File(dir, “f”); 6. } 7. }

假设当前目录为空,用户对这个目录有读写的权限,上面代码的运行结果是( )

a) Compilation fails.

b) Nothing is added to the file system.

c) Only a new file is created on the file system.

d) Only a new directory is created on the file system

e) Both a new file and a new directory are created on the file system.

145) 12. NumberFormat nf = NumberFormat.getInstance();

nf.setMaximumFractionDigits(4);

nf.setMinimumFractionDigits(2);

String a = nf.format(3.1415926);

String b = nf.format(2);

运行结果是,选择2个( )

a) The value of b is 2.

b) The value of a is 3.14

c) The value of b is 2.00.

d) The value of a is 3.141

e) The value of a is 3.1415

f) The value of a is 3.1416.

g) The value of b is 2.0000

146) 12. String csv = “Sue,5,true,3″;

Scanner scanner = new Scanner( csv );

scanner.useDelimiter(“,”);

int age = scanner.nextInt();运行结果是( )

a) Compilation fails.

b) After line 15, the value of age is 5

c) After line 15, the value of age is 3.

d) An exception is thrown at runtime.

147) C是java.io.Console的一个对象,下边那个方法可以从C中读取一行文本,选择2个( )

a) String s = c.readLine();

b) char[] c = c.readLine();

c) String s = c.readConsole();

d) char[] c = c.readConsole();

e) String s = c.readLine(“%s”, “name “);

f) char[] c = c.readLine(“%s”, “name “);

148) 11. String test = “a1

您可以返回查看更多面试信息:面试题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值