SCJP认证考什么

人气:115 ℃/2022-11-17 02:09:05

很多朋友不知道SCJP认证考什么,下面就让我们来看看吧。

SCJP认证是Java证书里一个基础证书,考试考的是Java方面的基础知识,以及考个人的实战经验与技术操作,SCJP认证考试总共有59 题,全英文试题,以电脑作答,时间 2 小时,及格标准要答对 61% 。

一、SCJP的介绍

SCJP是Java程序员认证,是一种Java认证考试。SCJP主要是测验Java程序设计概念及能力,内容偏向于Java语法以及JDK的内容;

二、SCJP证书的好处

SCJP是java程序员最基础的认证,考其他级别的java认证都需要先考过SCJP认证,可以说SCJP是一块敲门砖,通过Sun任何一门专业认证后,你将会收到Sun Microsystems总公司寄发的资格证书及徽章,并有权将通过Sun认证的标记印在个人名片上,代表个人技术能力的肯定;

三、SCJP考试日期

考试时间为每周一至周五,上午十点至下午五点,例假日除外;

四、SCJP考试方式

全英文试题,以电脑作答,在授权的Prometric考试中心参加考试;

五、考试题型

复选、填空和拖拽匹配。

SCJP认证是Java证书里一个基础证书,考试考的是Java方面的基础知识,以及考个人的实战经验与技术操作。SCJP认证考试总共有59 题,全英文试题,以电脑作答,时间 2 小时,及格标准要答对61%

SCJP认证

SCJP考试认证题集100道(有答案),干货!值得收藏

Question 1

Given:

11. public interface Status {

12. /* insert code here */ int MY_VALUE = 10;

13. }

Which three are valid on line 12? (Choose three.)

A. final

B. static

C. native

D. public

E. private

F. abstract

G. protected

Answer: ABD

Question 2

Given:

10. public class Bar {

11.static void foo(int...x) {

12. // insert code here

13. }

14. }

Which two code fragments, inserted independently at line 12, will allow

the class to compile? (Choose two.)

A. foreach(x) System.out.println(z);

B. for(int z : x) System.out.println(z); abcd

C. while( x.hasNext()) System.out.println( x.next());

D. for( int i=0; i< x.length; i ) System.out.println(x[i]);

Answer: BD

Question 3

Given:

11. public class Test {

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

13. int x =5;

14. boolean b1 = true;

15. boolean b2 = false;

16.

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

18. System.out.print(”l “);

19. System.out.print(”2 “);

20. if ((b2 = true) && b1)

21. System.out.print(”3 “);

22. }

23. }

What is the result?

A. 2

B. 3

C. 1 2

D. 2 3

E. 1 2 3

F. Compilation fails.

G. Au exceptional is thrown at runtime.

Answer: D

Question 4

4. Given:

31. // some code here

32. try {

33. // some code here

34. } catch (SomeException se) {

35. // some code here

36. } finally {

37. // some code here

38. }

Under which three circumstances will the code on line 37 be executed?

(Choose three.)

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.

Answer: BCE

lQuestion 5

Given:

10. interface Foo {}

11. class Alpha implements Foo { }

12. class Beta extends Alpha {}

13. class Delta extends Beta {

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

15. Beta x = new Beta();

16. // insert code here

17. }

18. }

Which code, inserted at line 16, will cause a

java.lang.ClassCastException?

A. Alpha a = x;

B. Foo f= (Delta)x;

C. Foo f= (Alpha)x;

D. Beta b = (Beta)(Alpha)x;

Answer: B

Question 6

Given:

? d is a valid, non-null Date object

? df is a valid, non-null DateFormat object set to the

current Locale

What outputs the current locales country name and the appropriate

version of d’s date?

A. Locale loc = Locale.getLocale();

System.out.println(loc.getDisplayCountry()

“ “ df.format(d));

B. Locale loc = Locale.getDefault();

System.out.println(loc.getDisplayCountry()

“ “ df.format(d));

C. Locale bc = Locale.getLocale();

System.out.println(loc.getDisplayCountry()

“ “ df.setDateFormat(d));

D. Locale loc = Locale.getDefault();

System.out.println(loc.getDispbayCountry()

“ “ df.setDateFormat(d));

Answer: B

Question 7

Given:

20. public class CreditCard {

21.

22. private String cardlD;

23. private Integer limit;

24. public String ownerName;

25.

26. public void setCardlnformation(String cardlD,

27. String ownerName,

28. Integer limit) {

29. this.cardlD = cardlD;

30. this.ownerName = ownerName;

31. this.limit = limit;

32. }

33. }

Which is true?

A. The class is fully encapsulated.

B. The code demonstrates polymorphism.

C. The ownerName variable breaks encapsulation.

D. The cardlD and limit variables break polymorphism.

E. The setCardlnformation method breaks encapsulation.

Answer: C

Question 8

Assume that country is set for each class.

Given:

10. public class Money {

11. private String country, name;

12. public getCountry() { return country; }

13.}

and:

24. class Yen extends Money {

25. public String getCountry() { return super.country; }

26. }

27.

28. class Euro extends Money {

29. public String getCountry(String timeZone) {

30. return super.getCountry();

31. }

32. }

Which two are correct? (Choose two.)

A. Yen returns correct values.

B. Euro returns correct values.

C. An exception is thrown at runtime.

D. Yen and Euro both return correct values.

E. Compilation fails because of an error at line 25.

F. Compilation fails because of an error at line 30.

Answer: BE

Question 9 abcd

Which Man class properly represents the relationship “Man has a best

friend who is a Dog”?

A. class Man extends Dog { }

B. class Man implements Dog { }

C. class Man { private BestFriend dog; }

D. class Man { private Dog bestFriend; }

E. class Man { private Dog<bestFriend> }

F. class Man { private BestFriend<dog> }

Answer: D

Question 10

Given:

11. public class Person {

12. private name;

13. public Person(String name) {

14. this.name = name;

15. }

16. public int hashCode() {

17. return 420;

18. }

19. }

Which is true?

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.

Answer: A

Question 11

Given:

23. Object [] myObjects = {

24. new integer(12),

25. new String(”foo”),

26. new integer(5),

27. new Boolean(true)

28. };

29. Arrays.sort(myObjects);

30. for( int i=0; i<myObjects.length; i ) {

31. System.out.print(myObjects[i].toString());

32. System.out.print(” “);

33. }

What is the result?

A. Compilation fails due to an error in line 23.

B. Compilation fails due to an error in line 29.

C. A ClassCastException occurs in line 29.

D. A ClassCastException occurs in line 31.

E. The value of all four objects prints in natural order.

Answer: C

Question 12

12. Given:

13. public class Pass {

14. public static void main(String [1 args) {

15. int x 5;

16. Pass p = new Pass();

17. p.doStuff(x);

18. System.out.print(” main x = “ x);

19. }

20.

21. void doStuff(int x) {

22. System.out.print(” doStuff x = “ x );

23. }

24. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. doStuffx = 6 main x = 6

D. doStuffx = 5 main x = 5

E. doStuffx = 5 main x = 6

F. doStuffx = 6 main x = 5

Answer: D

Question 13

Given:

10. package com.sun.scjp;

11. public class Geodetics {

12. public static final double DIAMETER = 12756.32; // kilometers

13. }

Which two correctly access the DIAMETER member of the Geodetics

class? (Choose two.)

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

Answer: AC

Question 14

Given:

10. class Nav{

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

12. }

13. public class Sprite{

14. // insert code here

15. }

Which code, inserted at line 14, allows the Sprite class to compile?

A. Direction d = NORTH;

B. Nav.Direction d = NORTH;

C. Direction d = Direction.NORTH;

D. Nav.Direction d = Nav.Direction.NORTH;

Answer: D

Question 15

Given:

10. interface Foo { int bar(); }

11. public class Sprite {

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

13. public void testFoo() {

14. fubar(

15. // insert code here

16.);

17. }

18. }

Which code, inserted at line 15, allows the class Sprite to compile?

A. Foo { public int bar() { return 1; } }

B. new Foo { public int bar() { return 1; } }

C. newFoo() { public int bar(){return 1; } }

D. new class Foo { public int bar() { return 1; } }

Answer: C

Question 16

Click the Exhibit button.

10. interface Foo {

11. int bar();

12. }

13.

14. public class Beta {

15.

16. class A implements Foo {

17. public int bar() { return 1; }

18. }

19.

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

21.

22. public void testFoo() {

23.

24. class A implements Foo {

25. public int bar() { return 2; }

26. }

27.

28. System.out.println( fubar( new A()));

29. }

30.

31. public static void main( String[] argv) {

32. new Beta().testFoo();

33. }

34. }

Which three statements are true? (Choose three.)

A. Compilation fails.

B. The code compiles and the output is 2.

C. If lines 16, 17 and 18 were removed, compilation would fail.

D. If lines 24, 25 and 26 were removed, compilation would fail.

E. If lines 16, 17 and 18 were removed, the code would compile and

the output would be 2.

F. If lines 24, 25 and 26 were removed, the code would compile and

the output would be 1.

Answer: BEF

Question 17

Given:

1. package sun.scjp;

2. public enum Color { RED, GREEN, BLUE }

1. package sun.beta;

2. // insert code here

3. public class Beta {

4. Color g = GREEN;

5. public static void main( String[] argv)

6. { System.out.println( GREEN); }

7. }

The class Beta and the enum Color are in different packages.

Which two code fragments, inserted individually at line 2 of the Beta

declaration, will allow this code to compile? (Choose two.)

A. import sun.scjp.Color.*;

B. import static sun.scjp.Color.*;

C. import sun.scjp.Color; import static sun.scjp.Color.*;

D. import sun.scjp.*; import static sun.scjp.Color.*;

E. import sun.scjp.Color; import static sun.scjp.Color.GREEN;

Answer: CE

Question 18

Given:

1. public interface A {

2. String DEFAULT_GREETING = “Hello World”;

3. public void method1();

4. }

A programmer wants to create an interface called B that has A as its

parent. Which interface declaration is correct?

A. public interface B extends A { }

B. public interface B implements A {}

C. public interface B instanceOf A {}

D. public interface B inheritsFrom A { }

Answer: A

Question 19

Given:

1. class TestA {

2. public void start() { System.out.println(”TestA”); }

3. }

4. public class TestB extends TestA {

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

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

7. ((TestA)new TestB()).start();

8. }

9. }

What is the result?

A. TestA

B. TestB

C. Compilation fails.

D. An exception is thrown at runtime.

Answer: B

Question 20

Given:

1. interface TestA { String toString(); }

2. public class Test {

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

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

5. public String toString() { return “test”; }

6. });

7. }

8. }

What is the result?

A. test

B. null

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 1.

E. Compilation fails because of an error in line 4.

F. Compilation fails because of an error in line 5.

Answer: A

Question 21

Given:

11. public abstract class Shape {

12. int x;

13. int y;

14. public abstract void draw();

15. public void setAnchor(int x, int y) {

16. this.x = x;

17. this.y = y;

18. }

19. }

and a class Circle that extends and fully implements the Shape class.

Which is correct?

A. Shape s = new Shape();

s.setAnchor(10,10);

s.draw();

B. Circle c = new Shape();

c.setAnchor(10,10);

c.draw();

C. Shape s = new Circle();

s.setAnchor(10,10);

s.draw();

D. Shape s = new Circle();

s->setAnchor(10,10);

s->draw();

E. Circle c = new Circle();

c.Shape.setAnchor(10,10);

c.Shape.draw();

Answer: C

Question 22

Given:

10. abstract public class Employee {

11. protected abstract double getSalesAmount();

12. public double getCommision() {

13. return getSalesAmount() * 0.15;

14. }

15. }

16. class Sales extends Employee {

17. // insert method here

18. }

Which two methods, inserted independently at line 17, correctly

complete the Sales class? (Choose two.)

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

Answer: BD

Question 23

Given:

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

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

Which class correctly uses the Data interface and Info class?

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() { /*d something */ }

public void load() { /*do something */ }

}

E. public class Employee implements Info extends Data {

public void load() { /*do something */ }

public void Info.load(){ /*do something*/ }

}

F. public class Employee extends Info implements Data{

public void Data.load() { /*do something*/ }

public void Info.load() { /*do something*/ }

}

Answer: A

Question 24

Given:

11. public abstract class Shape {

12. private int x;

13. private int y;

14. public abstract void draw();

15. public void setAnchor(int x, int y) {

16. this.x = x;

17. this.y = y;

18. }

19. }

Which two classes use the Shape class correctly? (Choose two.)

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 abstract class Circle implements Shape {

private int radius;

public void draw();

}

E. public class Circle extends Shape {

private int radius;

public void draw() {/* code here */}

}

F. public abstract class Circle implements Shape {

private int radius;

public void draw() { / code here */ }

}

Answer: BE

Question 25

Which two classes correctly implement both the java.lang.Runnable

and the java.lang.Clonable interfaces? (Choose two.)

A. public class Session

implements Runnable, Clonable {

public void run();

public Object clone();

}

B. public class Session

extends Runnable, 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 abstract class Session

implements Runnable, Clonable {

public void run() { / do something */ }

public Object clone() { /*make a copy */ }

}

E. public class Session

implements Runnable, implements Clonable {

public void run() { / do something */ }

public Object clone() { / make a copy */ }

}

Answer: CD

Question26

Click the Exhibit button.

1. public class GoTest {

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

3. Sente a = new Sente(); a.go();

4. Goban b = new Goban(); b.go();

5. Stone c = new Stone(); c.go();

6. }

7. }

8.

9. class Sente implements Go {

10. public void go() { System.out.println(”go in Sente.”); }

11. }

12.

13. class Goban extends Sente {

14. public void go() { System.out.println(”go in Goban”); }

15. }

16.

17. class Stone extends Goban implements Go { }

18.

19. interface Go { public void go(); }

What is the result?

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

E. Compilation fails because of an error in line 17.

Answer: C

Question 27

Given:

11. public static void parse(String str) {

12. try {

13. float f= Float.parseFloat(str);

14. } catch (NumberFormatException nfe) {

15. f= 0;

16. } finally {

17. System.out.println(f);

18. }

19. }

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

21. parse(”invalid”);

22. }

What is the result?

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.

Answer: B

Question 28

Click the Exhibit button.

1. public class Test {

2. int x= 12;

3. public void method(int x) {

4. x =x;

5. System.out.println(x);

6. }

7. }

Given:

34. Test t = new Test();

35. t.method(5);

What is the output from line 5 of the Test class?

A. 5

B. 10

C. 12

D. 17

E. 24

Answer: B

Question 28

Given:

55. int []x= {1, 2,3,4, 5};

56.int y[] =x;

57. System.out.println(y[2]);

Which is true?

A. Line 57 will print the value 2.

B. Line 57 will print the value 3.

C. Compilation will fail because of an error in line 55.

D. Compilation will fail because of an error in line 56.

Answer: B

Question 30

Given:

35. String #name = “Jane Doe”;

36.int$age=24;

37. Double_height = 123.5;

38. double~temp = 37.5;

Which two are true? (Choose two.)

A. Line 35 will not compile.

B. Line 36 will not compile.

C. Line 37 will not compile.

D. Line 38 will not compile.

Answer: AD

Question 31

Which two code fragments correctly create and initialize a static array

of int elements? (Choose two.)

A. static final int[] a = { 100,200 };

B. static final int[] a;

static { a=new int[2]; a[0]=100; a[1]=200; }

C. static final int[] a = new int[2] { 100,200 };

D. static final int[] a;

static void init() { a = new int[3]; a[0]=100; a[1]=200; }

Answer: AB

Question 32

Given:

11. public class Ball {

12. public enum Color { RED, GREEN, BLUE };

13. public void foo() {

14. // insert code here

15. { System.out.println(c); }

16. }

17. }

Which code inserted at line 14 causes the foo method to print RED,

GREEN, and BLUE?

A. for( Color c : Color.values())

B. for( Color c = RED; c <= BLUE; c )

C. for( Color c; c.hasNext() ; c.next())

D. for( Color c = Color[0]; c <= Color[2]; c )

E. for( Color c = Color.RED; c <= Color.BLUE; c )

Answer: A

Question 33

Given:

10. public class Fabric

11. public enum Color {

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

13. private final int rgb;

14. Color( int rgb) { this.rgb = rgb; }

15. public int getRGB() { return rgb; }

16. };

17. public static void main( String[] argv) {

18. // insert code here

19. }

20. }

Which two code fragments, inserted independently at line 18, allow the

Fabric class to compile? (Choose two.)

A. Color skyColor = BLUE;

B. Color treeColor = Color.GREEN;

C. Color purple = new Color( 0xff00ff);

D. if( RED.getRGB() < BLUE.getRGB() ) {}

E. Color purple = Color.BLUE Color.RED;

F. if( Color.RED.ordinal() < Color.BLUE.ordinal() ) {}

Answer: BF

Question 34

Given:

11. public enum Title {

12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”);

13. private final String title;

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

15. public String format(String last, String first) {

16. return title “ “ first “ “ last;

17. }

18. }

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

20. System.out.println(Title.MR.format(”Doe”, “John”));

21. }

What is the result?

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.

E. Compilation fails because of an error in line 20.

Answer: A

Question 35

Given:

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

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

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

14. for (int i: someArray) System.out.print(i “ “)

15. }

‘What is the result?

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.

E. A ClassCastException is thrown at runtime.

Answer: A

Question 36

Given:

10. class Foo {

11. static void alpha() { /* more code here */ }

12. void beta() { /* more code here */ }

13. }

Which two are true? (Choose two.)

A. Foo.beta() is a valid invocation of beta().

B. Foo.alpha() is a valid invocation of alpha().

C. Method beta() can directly call method alpha().

D. Method alpha() can directly call method beta().

Answer: BC

Question 37

A programmer needs to create a logging method that can accept an

arbitrary number of arguments. For example, it may be called in these

ways:

logIt(”log message 1 “);

logIt(”log message2”,”log message3”);

logIt(”log message4”, “log message5”, “log message6);

Which declaration satisfies this requirement?

A. public void logIt(String * msgs)

B. public void logIt(String [] msgs)

C. public void logIt(String... msgs)

D. public void logIt(String msg1, String msg2, String msg3)

Answer: C

Question 38

A programmer is designing a class to encapsulate the information

about an inventory item. A JavaBeans component is needed to

do this. The Inventoryltem class has private instance variables to store

the item information:

10. private int itemId;

11. private String name;

12. private String description;

Which method signature follows the JavaBeans naming standards for

modifying the itemld instance variable?

A. itemID(int itemId)

B. update(int itemId)

C. setItemId(int itemId)

D. mutateItemId(int itemId)

E. updateItemID(int itemId)

Answer: C

Question 39

Click the Exhibit button.

1. public class A {

2.

3. private int counter = 0;

4.

5. public static int getInstanceCount() {

6. return counter;

7. }

8.

9. public A() {

10. counter ;

11. }

12.

13. }

Given this code from Class B:

25.A a1 =new A();

26. A a2 =new A();

27. A a3 =new A();

28. System.out.printIn(A.getInstanceCount() );

What is the result?

A. Compilation of class A fails.

B. Line 28 prints the value 3 to System.out.

C. Line 28 prints the value 1 to System.out.

D. A runtime error occurs when line 25 executes.

E. Compilation fails because of an error on line 28.

Answer: A

Question 40

A JavaBeans component has the following field:

11. private boolean enabled;

Which two pairs of method declarations follow the JavaBeans standard

for accessing this field? (Choose two.)

A. public void setEnabled( boolean enabled)

public boolean getEnabled()

B. public void setEnabled( boolean enabled)

public void isEnabled()

C. public void setEnabled( boolean enabled)

public boolean isEnabled()

D. public boolean setEnabled( boolean enabled)

public boolean getEnabled()

Answer: AC

Question 41

41. Given:

10. class One {

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

12. }

13. class Two extends One {

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

15. }

16. class Three extends Two {

17. // insert method here

18. }

Which two methods, inserted individually, correctly complete the Three

class? (Choose two.)

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

Answer: CD

Question 42

Given:

10. class One {

11. void foo() {}

12. }

13. class Two extends One {

14. //insert method here

15. }

Which three methods, inserted individually at line 14, will correctly

complete class Two? (Choose three.)

A. int 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 */ }

Answer: BCE

Question 43

Click the Exhibit button.

1. public interface A {

2. public void doSomething(String thing);

3. }

1. public class AImpl implements A {

2. public void doSomething(String msg) { }

3. }

1. public class B {

2. public A doit() {

3. // more code here

4. }

5.

6. public String execute() {

7. // more code here

8. }

9. }

1. public class C extends B {

2. public AImpl doit() {

3. // more code here

4. }

5.

6. public Object execute() {

7. // more code here

8. }

9. }

Which statement is true about the classes and interfaces in the

exhibit?

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.

Answer: C

Question 44

Click the Exhibit button.

1. public class A {

2. public String doit(int x, int y) {

3. return “a”;

4. }

5.

6. public String doit(int... vals) {

7. return “b”;

8. }

9. }

Given:

25. A a=new A();

26. System.out.println(a.doit(4, 5));

What is the result?

A. Line 26 prints “a” to System.out.

B. Line 26 prints ‘b” to System.out.

C. An exception is thrown at line 26 at runtime.

D. Compilation of class A will fail due to an error in line 6.

Answer: A

Question 45

Given:

1. public class A {

2. public void doit() {

3. }

4. public String doit() {

5. return “a”;

6. }

7. public double doit(int x) {

8. return 1.0;

9. }

10.}

What is the result?

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.

Answer: C

Question 46

46. Given:

10. class Line {

11. public static class Point { }

12. }

13.

14. class Triangle {

15. // insert code here

16. }

Which code, inserted at line 15, creates an instance of the Point class

defined in Line?

A. Point p = new Point();

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

C. The Point class cannot be instatiated at line 15.

D. Line 1 = new Line() ; 1.Point p = new 1.Point();

Answer: B

Question 47

Given:

10. class Line {

11. public class Point { public int x,y; }

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

13. }

14. class Triangle {

15. public Triangle() {

16. // insert code here

17. }

18. }

Which code, inserted at line 16, correctly retrieves a local instance of a

Point object?

A. Point p = Line.getPoint();

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

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

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

Answer: D

Question 48

Given:

10. class One {

11. public One() { System.out.print(1); }

12. }

13. class Two extends One {

14. public Two() { System.out.print(2); }

15. }

16. class Three extends Two {

17. public Three() { System.out.print(3); }

18. }

19. public class Numbers{

20. public static void main( String[] argv) { new Three(); }

21. }

What is the result when this code is executed?

A. 1

B. 3

C. 123

D. 321

E. The code rims with no output.

Answer: C

Question 49

Click the Exhibit button.

11. class Person {

12. String name = “No name’;

13. public Person(String nm) { name = nm; }

14. }

15.

16. class Employee extends Person {

17. String emplD = “0000”;

18. public Employee(String id) { empID = id; }

19. }

20.

21. public class EmployeeTest {

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

23. Employee e = new Employee(”4321”);

24. System.out.println(e.empID);

25. }

26. }

What is the result?

A. 4321

B. 0000

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 18.

Answer: D

Question 50

Given:

1. public class Plant {

2. private String name;

3. public Plant(String name) { this.name = name; }

4. public String getName() { return name; }

5. }

1. public class Tree extends Plant {

2. public void growFruit() { }

3. public void dropLeaves() { }

4. }

Which is true?

A. The code will compile without changes.

B. The code will compile if public Tree() { Plant(); } is added to the

Tree class.

C. The code will compile if public Plant() { Tree(); } is added to the

Plant class.

D. The code will compile if public Plant() { this(”fern”); } is added to

the Plant class.

E. The code will compile if public Plant() { Plant(”fern”); } is added to

the Plant class.

Answer: D

Question 51

Click the Exhibit button.

11. public class Bootchy {

12. int bootch;

13. String snootch;

14.

15. public Bootchy() {

16. this(”snootchy”);

17. System.out.print(”first “);

18. }

19.

20. public Bootchy(String snootch) {

21. this(420, “snootchy”);

22. System.out.print(”second “);

23. }

24.

25. public Bootchy(int bootch, String snootch) {

26. this.bootch = bootch;

27. this.snootch = snootch;

28. System.out.print(”third “);

29. }

30.

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

32. Bootchy b = new Bootchy();

33. System.out.print(b.snootch “ “ b.bootch);

34. }

35. }

What is the result?

A. snootchy 420 third second first

B. snootchy 420 first second third

C. first second third snootchy 420

D. third second first siiootchy 420

E. third first second snootchy 420

F. first second first third snootchy 420

Answer: D

Question 52

Given:

11. public class Test {

12. public enum Dogs {collie, harrier, shepherd};

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

14. Dogs myDog = Dogs.shepherd;

15. switch (myDog) {

16. case collie:

17. System.out.print(”collie “);

18. case default:

19. System.out.print(”retriever “);

20. case harrier:

21. System.out.print(”harrier “);

22. }

23. }

24. }

‘What is the result?

A. harrier

B. shepherd

C. retriever

D. Compilation fails.

E. retriever harrier

F. An exception is thrown at runtime.

Answer: D

Question 53

Given:

12. public class Test {

13. public enum Dogs {collie, harrier};

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

15. Dogs myDog = Dogs.collie;

16. switch (myDog) {

17. case collie:

18. System.out.print(”collie “);

19. case harrier:

20. System.out.print(”harrier “);

21. }

22. }

23. }

What is the result?

A. collie

B. harrier

C. Compilation fails.

D. collie harrier

E. An exception is thrown at runtime.

Answer: D

Question 54

Given:

11. public void testIfA() {

12. if(testIfB(”True”)) {

13. System.out.println(”True”);

14. } else {

15. System.out.println(”Not true”);

16. }

17. }

18. public Boolean testIfB(String str) {

19. return Boolean.valueOf(str);

20. }

What is the result when method testIfA is invoked?

A. True

B. Not true

C. An exception is thrown at runtime.

D. Compilation fails because of an error at line 12.

E. Compilation fails because of an error at line 19.

Answer: A

Question 55

Given:

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

12. Integer i = uew Integer(1) new Integer(2);

13. switch(i) {

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

15. default: System.out.println(”other”); break;

16. }

17. }

‘What is the result?

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.

Answer: A

Question 56

Given:

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

12. String str = “null’;

13. if (str == null) {

14. System.out.println(”null”);

15. } else (str.length() == 0) {

16. System.out.println(”zero”);

17. } else {

18. System.out.println(”some”);

19. }

20. }

‘What is the result?

A. null

B. zero

C. some

D. Compilation fails.

E. An exception is thrown at runtime.

Answer: D

Question 57

Given:

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

12.if(pi>3) {

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

14. }

15. else {

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

17. }

18. finally {

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

20. }

‘What is the result?

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.

Answer: A

Question 58

Given:

10.int x=0;

11.int y 10;

12. do {

l3. y--;

14. x;

15. } while (x < 5);

16. System.out.print(x “,“ y);

What is the result?

A. 5,6

B. 5,5

C. 6,5

D. 6,6

Answer: B

Question 59

Given:

25.intx=12;

26. while (x < 10) {

27. x--;

28. }

29. System.out.print(x);

What is the result?

A. 0

B. 10

C. 12

D. Line 29 will never be reached.

Answer: C

Question 60

Given:

35. int x= 10;

36. do {

37. x--;

38. } while(x< 10);

How many times will line 37 be executed?

A. ten times

B. zero times

C. one to me times

D. more than ten times

Answer: D

Question 61

Give:

11. public static Iterator reverse(List list) {

12. Collections.reverse(list);

13. return list.iterator();

14. }

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

16. List list = new ArrayList();

17. list.add(” 1”); list.add(”2”); list.add(”3”);

18. for (Object obj: reverse(list))

19. System.out.print(obj “,”);

20. }

‘What is the result?

A. 3,2, 1,

B. 1, 2, 3,

C. Compilation fails.

D. The code runs with no output.

E. An exception is thrown at runtime.

Answer: C

Question 62

Given:

11. public static Collection get() {

12. Collection sorted = new LinkedList();

13. sorted.add(’B”); sorted.add(”C”); sorted.add(”A”);

14. return sorted;

15. }

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

17. for (Object obj: get()) {

18. System.out.print(obj “, “);

19. }

20. }

What is the result?

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.

Answer: B

Question 63

Given:

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

12. for (int i=0;i<= 10;i ){

13. if( i>6) break;

14. }

15. System.out.println(i);

16. }

What is the result?

A. 6

B. 7

C. 10

D. 11

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: E

Question 64

Given:

8. public class test {

9. public static void main(String [] a) {

10. assert a.length == 1;

11. }

12. }

Which two will produce an AssertionError? (Choose two.)

A. java test

B. java -ea test

C. java test file1

D. java -ea test file1

E. java -ea test file1 file2

F. java -ea:test test file1

Answer: BE

Question 65

Given:

12. public class AssertStuff {

13.

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

15. int x= 5;

16. int y= 7;

17.

18. assert (x> y): “stuff”;

19. System.out.println(”passed”);

20. }

21. }

And these command line invocations:

java AssertStuff

java -ea AssertStuff

What is the result?

A. passed

stuff

B. stuff

passed

C. passed

An AssertionError is thrown with the word “stuff” added to the stack

trace.

D. passed

An AssertionError is thrown without the word “stuff” added to the

stack trace.

E. passed

An AssertionException is thrown with the word “stuff” added to the

stack trace.

F. passed

An AssertionException is thrown without the word “stuff” added to the

stack trace.

Answer: C

Question 66

Click the Exhibit button.

1. public class Test {

2.

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

4. boolean assert = true;

5. if(assert) {

6. System.out.println(”assert is true”);

7. }

8. }

9.

10. }

Given:

javac -source 1.3 Test.java

What is the result?

A. Compilation fails.

B. Compilation succeeds with errors.

C. Compilation succeeds with warnings.

D. Compilation succeeds without warnings or errors.

Answer: C

Question 67

Given:

23.int z=5;

24.

25. public void stuff1(int x) {

26. assert (x> 0);

27. switch(x) {

28. case 2: x= 3;

29. default: assert false; } }

30.

31. private void stuff2(int y) { assert (y < 0); }

32.

33. private void stuff3() { assert (stuff4O); }

34.

35. private boolean stuff4() { z = 6; return false; }

Which is true?

A. All of the assert statements are used appropriately.

B. Only the assert statement on line 31 is used appropriately.

C. The assert statements on lines 29 and 31 are used appropriately.

D. The assert statements on lines 26 and 29 are used appropriately.

E. The assert statements on lines 29 and 33 are used appropriately.

F. The assert statements on lines 29, 31, and 33 are used

appropriately.

G. The assert statements on lines 26, 29, and 31 are used

appropriately.

Answer: C

Question 68

Click the Exhibit button.

SomeException:

1. public class SomeException {

2. }

Class A:

1. public class A {

2. public void doSomething() { }

3. }

Class B:

1. public class B extends A {

2. public void doSomething() throws SomeException { }

3. }

Which is true about the two classes?

A. Compilation of both classes will fail.

B. Compilation of both classes will succeed.

C. Compilation of class A will fail. Compilation of class B will succeed.

D. Compilation of class B will fail. Compilation of class A will succeed.

Answer: D

Question 69

Click the Exhibit button.

Class TestException

1. public class TestException extends Exception {

2. }

Class A:

1. public class A {

2.

3. public String sayHello(String name) throws TestException {

4.

5. if(name == null) {

6. throw new TestException();

7. }

8.

9. return “Hello “ name;

10. }

11.

12. }

A programmer wants to use this code in an application:

45. A a=new A();

46. System.out.println(a.sayHello(”John”));

Which two are true? (Choose two.)

A. Class A will not compile.

B. Line 46 can throw the unchecked exception TestException.

C. Line 45 can throw the unchecked exception TestException.

D. Line 46 will compile if the enclosing method throws a TestException.

E. Line 46 will compile if enclosed in a try block, where TestException

is caught.

Answer: DE

Question 70

Given:

33. try {

34. // some code here

35. } catch (NullPointerException e1) {

36. System.out.print(”a”);

37. } catch (RuntimeException e2) {

38. System.out.print(”b”);

39. } finally {

40. System.out.print(”c”);

41. }

What is the result if a NullPointerException occurs on line 34?

A. c

B. a

C. ab

D. ac

E. bc

F. abc

Answer: D

Question 71

Given:

11.classA {

12. public void process() { System.out.print(”A,”); } }

13. class B extends A {

14. public void process() throws IOException {

15. super.process();

16. System.out.print(”B,”);

17. throw new IOException();

18. } }

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

20. try { new B().process(); }

21. catch (IOException e) { System.out.println(”Exception”); } }

What is the result?

A. Exception

B. A,B,Exception

C. Compilation fails because of an error in line 20.

D. Compilation fails because of an error in line 14.

E. A NullPointerException is thrown at runtime.

Answer: D

Question 72

Given:

11.classA {

12. public void process() { System.out.print(”A “); } }

13. class B extends A {

14. public void process() throws RuntimeException {

15. super.process();

16. if (true) throw new RuntimeException();

17. System.out.print(“B”); }}

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

19. try { ((A)new B()).process(); }

20. catch (Exception e) { System.out.print(”Exception “); }

21. }

What is the result?

A. Exception

B. A Exception

C. A Exception B

D. A B Exception

E. Compilation fails because of an error in line 14.

F. Compilation fails because of an error in line 19.

Answer: B

Question 73

Given:

11. static classA {

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

13. }

14. static class B extends A {

15. void process() { System.out.println(”B “); }

16. }

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

18.A a=new B();

19. a.process();

20.}

What is the result?

A. B

B. The code runs with no output.

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 15.

E. Compilation fails because of an error in line 18.

F. Compilation fails because of an error in line 19.

Answer: F

Question 74

Given:

11. static class A {

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

13. }

14. static class B extends A {

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

16. }

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

18. new B().process();

19. }

What is the result?

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.

E. Compilation fails because of an error in line 18.

Answer: A

Question 75

Given:

84. try {

85. ResourceConnection con = resourceFactory.getConnection();

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

87. info = r.getData();

88. con.close();

89. } catch (ResourceException re) {

90. errorLog.write(re.getMessage());

91. }

92. return info;

Which is true if a ResourceException is thrown on line 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.

Answer: C

Question 76

Click the Exhibit button.

1. public class A {

2. public void method1() {

3. B b=new B();

4. b.method2();

5. // more code here

6. }

7. }

1. public class B {

2. public void method2() {

3.C c=new C();

4. c.method3();

5. // more code here

6. }

7. }

1. public class C {

2. public void method3() {

3. // more code here

4. }

5. }

Given:

25. try {

26. A a=new A();

27. a.method1();

28. } catch (Exception e) {

29. System.out.print(”an error occurred”);

30. }

Which two are true if a NullPointerException is thrown on line 3 of

class C? (Choose two.)

A. The application will crash.

B. The code on line 29 will be executed.

C. The code on line 5 of class A will execute.

D. The code on line 5 of class B will execute.

E. The exception will be propagated back to line 27.

Answer: BE

Question 77

Click the Exhibit button.

1. public class A {

2. public void method1() {

3. try {

4. B b=new B();

5. b.method2();

6. // more code here

7. } catch (TestException te) {

8. throw new RuntimeException(te);

9. }

6. }

7. }

1. public class B {

2. public void method2() throws TestException {

3. // more code here

4. }

5. }

1. public class TestException extends Exception {

2. }

Given:

31. public void method() {

32. A a=new A();

33. a.method1();

34. }

Which is true if a TestException is thrown on line 3 of class B?

A. Line 33 must be called within a try block.

B. The exception thrown by method1 in class A is not required to be

caught.

C. The method declared on line 31 must be declared to throw a

RuntimeException.

D. On line 5 of class A, the call to method2 of class B does not need to

be placed in a try/catch block.

Answer: B

Question 78

Given:

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

12. try {

13. args=null;

14. args[0] = “test”;

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

16. } catch (Exception ex) {

17. System.out.println(”Exception”);

18. } catch (NullPointerException npe) {

19. System.out.println(”NullPointerException”);

20. }

21. }

What is the result?

A. test

B. Exception

C. Compilation fails.

D. NullPointerException

Answer: C

Question 79

Given:

11. static void test() throws Error {

12. if (true) throw new AssertionError();

13. System.out.print(”test “);

14. }

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

16. try { test(); }

17. catch (Exception ex) { System.out.print(”exception “); }

18. System.out.print(”elld “);

19. }

What is the result?

A. end

B. Compilation fails.

C. exception end

D. exception test end

E. A Throwable is thrown by main.

F. An Exception is thrown by main.

Answer: E

Question 80

Given:

11. static void test() {

12. try {

13. String x=null;

14. System.out.print(x.toString() “ “);

15. }

16. finally { System.out.print(“finally “); }

17. }

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

19. try { test(); }

20. catch (Exception ex) { System.out.print(”exception “); }

21. }

What is the result?

A. null

B. finally

C. null finally

D. Compilation fails.

E. finally exception

Answer: E

Question 81

Given:

11. static void test() throws RuntimeException {

12. try {

13. System.out.print(”test “);

14. throw new RuntimeException();

15. }

16. catch (Exception ex) { System.out.print(”exception “); }

17. }

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

19. try { test(); }

20. catch (RuntimeException ex) { System.out.print(”runtime “); }

21. System.out.print(”end “);

22. }

What is the result?

A. test end

B. Compilation fails.

C. test runtime end

D. test exception end

E. A Throwable is thrown by main at runtime.

Answer: D

Question 82

Given a method that must ensue that its parameter is not null:

11. public void someMethod(Object value) {

12. // check for null value

....

20. System.out.println(value.getClass());

21. }

What, inserted at line 12, is the appropriate way to handle a null

value?

A. assert value == null;

B. assert value !null, “value is null”;

C. if (value == null) {

throw new AssertionException(”value is null”);

D. if (value == null) {

throw new IllegalArgumentException(”value is null”);

Answer: D

Question 83

Click the Exhibit button.

10. public class ClassA {

11. public void methodA() {

12. ClassB classB = new ClassB();

13. classB.getValue();

14. }

15. }

And:

20. class ClassB {

21. public ClassC classC;

22.

23. public String getValue() {

24. return classC.getValue();

25. }

26. }

And:

30. class ClassC {

31. public String value;

32.

33. public String getValue() {

34. value = “ClassB”;

35. return value;

36. }

37. }

Given:

ClassA a = new ClassA();

a.methodA();

What is the result?

A. Compilation fails.

B. ClassC is displayed.

C. The code runs with no output.

D. An exception is thrown at runtime.

Answer: D

Question 84

Given:

10. public class Foo {

11. static int[] a;

12. static { a[0]=2; }

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

14. }

Which exception or error will be thrown when a programmer attempts

to run this code?

A. java.lang. StackOverflowError

B. java.lang.IllegalStateException

C. java.lang.ExceptionlnlnitializerError

D. java.lang.ArraylndexOutOfBoundsException

Answer: C

Question 85

Given:

10. public class ClassA {

11. public void count(int i) {

12. count( i);

13. }

14. }

And:

20. ClassA a = new ClassA();

21. a.count(3);

Which exception or error should be thrown by the virtual machine?

A. StackOverflowError

B. NullPointerException

C. NumberFormatException

D. IllegalArgumentException

E. ExceptionlnlnitializerError

Answer: A

Question 86

Given:

1. public class Boxer1 {

2. Integer i;

3. int x;

4. public Boxer1(int y) {

5. x=i y;

6. System.out.println(x);

7. }

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

9. new Boxer1(new Integer(4));

10. }

11. }

What is the result?

A. The value “4” is printed at the command line.

B. Compilation fails because of an error in line 5.

C. Compilation fails because of an error in line 9.

D. A NullPointerException occurs at runtime.

E. A NumberFormatException occurs at runtime.

F. An IllegalStateException occurs at runtime.

Answer: D

Question 87

Given:

1. public class TestString 1 {

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

3. String str = “420”;

4. str = 42;

5. System.out.print(str);

6. }

7. }

What is the output?

A. 42

B. 420

C. 462

D. 42042

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: D

Question 88

Given:

11. class Converter {

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

13. Integer i = args[0];

14. int j = 12;

15. System.out.println(”It is “ (j==i) “that j==i.”);

16. }

17. }

What is the result when the programmer attempts to compile the code

and run it with the command java Converter 12?

A. It is true that j==i.

B. It is false that j==i.

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 13.

Answer: D

Question 89

Given this method in a class:

21. public String toString() {

22. StringBuffer buffer = new StringBuffer();

23. buffer.append(’<’);

24. buffer.append(this.name);

25. buffer.append(’>’);

26. return buffer.toString();

27. }

Which is true?

A. This code is NOT thread-safe.

B. The programmer can replace StringBuffer with StringBuilder with no

other changes.

C. This code will perform well and converting the code to use

StringBuilder will not enhance the performance.

D. This code will perform poorly. For better performance, the code

should be rewritten: return “<“ this.name “>”;

Answer: B

Question 90

Given:

1. public class MyLogger {

2. private StringBuilder logger = new StringBuuilder();

3. public void log(String message, String user) {

4. logger.append(message);

5. logger.append(user);

6. }

7. }

The programmer must guarantee that a single MyLogger object works

properly for a multi-threaded system. How must this code be changed

to be thread-safe?

A. synchronize the log method

B. replace StringBuilder with StringBuffer

C. No change is necessary, the current MyLogger code is already

thread-safe.

D. replace StringBuilder with just a String object and use the string

concatenation ( =) within the log method

Answer: A

Question 91

Given:

11. public String makinStrings() {

12. String s = “Fred”;

13. s = s “47”;

14. s = s.substring(2, 5);

15. s = s.toUpperCase();

16. return s.toString();

17. }

How many String objects will be created when this method is invoked?

A. 1

B. 2

C. 3

D. 4

E. 5

F. 6

Answer: C

Question 92

Given:

1. public class TestString3 {

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

3. // insert code here

5. System.out.println(s);

6. }

7. }

Which two code fragments, inserted independently at line 3, generate

the output 4247? (Choose two.)

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”);

Answer: BE

Question 93

Given:

11. public class Yikes {

12.

13. public static void go(Long n) {System.out.println(”Long “);}

14. public static void go(Short n) {System.out.println(”Short “);}

15. public static void go(int n) {System.out.println(”int “);}

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

17. short y= 6;

18. long z= 7;

19. go(y);

20. go(z);

21. }

22. }

What is the result?

A. int Long

B. Short Long

C. Compilation fails.

D. An exception is thrown at runtime.

Answer: A

Question 94

Given:

12. public class Wow {

13. public static void go(short n) {System.out.println(”short”); }

14. public static void go(Short n) {System.out.println(”SHORT”);}

15. public static void go(Long n) {System.out.println(” LONG”); }

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

17. Short y= 6;

18.int z=7;

19. go(y);

20. go(z);

21. }

22. }

What is the result?

A. short LONG

B. SHORT LONG

C. Compilation fails.

D. An exception is thrown at runtime.

Answer: C

Question 95

Given:

10. class MakeFile {

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

12. try {

13. File directory = new File(”d”);

14. File file = new File(directory,”f”);

15. if(!file.exists()) {

16. file.createNewFile();

17. }

18. } catch (IOException e) {

19. e.printStackTrace

20. }

21. }

22. }

The current directory does NOT contain a directory named “d.”

Which three are true? (Choose three.)

A. Line 16 is never executed.

B. An exception is thrown at runtime.

C. Line 13 creates a File object named “d.”

D. Line 14 creates a File object named “f.’

E. Line 13 creates a directory named “d” in the file system.

F. Line 16 creates a directory named “d” and a file ‘f’ within it in the

file system.

G. Line 14 creates a file named ‘f’ inside of the directory named “d” in

the file system.

Answer: BCD

Question 96

When comparing java.io.BufferedWriter to java.io.FileWriter, which

capability exists as a method in only one of the two?

A. closing the stream

B. flushing the stream

C. writing to the stream

D. marking a location in the stream

E. writing a line separator to the stream

Answer: E

Question 97

Given:

12. import java.io.*;

13. public class Forest implements Serializable {

14. private Tree tree = new Tree();

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

16. Forest f= new Forest();

17. try {

18. FileOutputStream fs = new FileOutputStream(”Forest.ser”);

19. ObjectOutputStream os = new ObjectOutputStream(fs);

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

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

22. } }

23.

24. class Tree { }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. An instance of Forest is serialized.

D. A instance of Forest and an instance of Tree are both serialized.

Answer: B

Question 98

Click the Exhibit button.

1. import java.io.*;

2. public class Foo implements Serializable {

3. public int x, y;

4. public Foo( int x, int y) { this.x = x; this.y = y; }

5.

6. private void writeObject( ObjectOutputStream s)

7. throws IOException {

8. s.writeInt(x); s.writeInt(y)

9. }

10.

11. private void readObject( ObjectInputStream s)

12. throws IOException, ClassNotFoundException {

13.

14. // insert code here

15.

16. }

17. }

Which code, inserted at line 14, will allow this class to correctly

serialize and deserialize?

A. s.defaultReadObject();

B. this = s.defaultReadObject();

C. y = s.readInt(); x = s.readInt();

D. x = s.readInt(); y = s.readInt();

Answer: D

Question 99

Which three concerning the use of the java.io.Serializable interface are

true? (Choose three.)

A. Objects from classes that use aggregation cannot be serialized.

B. Art object serialized on one JVM can be successfully deserialized on

a different JVM.

C. The values in fields with the volatile modifier will NOT survive

serialization and deserialization.

D. The values in fields with the transient modifier will NOT survive

serialization and deserialization.

E. It is legal to serialize an object of a type that has a supertype that

does NOT implement java.io.Serializable.

Answer: BDE

Question 100

Assuming that the serializeBanana() and the deserializeBanana()

methods will correctly use Java serialization and given:

13. import java.io.*;

14. class Food implemertts Serializable {int good = 3;}

15. class Fruit externds Food {int juice = 5;}

16. public class Banana extends Fruit {

17. int yellow = 4;

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

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

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

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

22. System.out.println(”restore “ b2.yellow b2.juice b2.good);

24. }

25. // more Banana methods go here

50. }

‘What is the result?

A. restore 400

B. restore 403

C. restore 453

D. Compilation fails.

E. An exception is thrown at runtime.

Answer: C

scjp证书

推荐

首页/电脑版/网名
© 2026 NiBaKu.Com All Rights Reserved.