178
Sun 310-055 Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0 Q&A Version 12.0

TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Embed Size (px)

Citation preview

Page 1: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Sun 310-055

Sun Certified Programmer for the Java 2 Platform,Standard Edition 5.0

Q&A

Version 12.0

Page 2: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 2 -

Important Note, Please Read Carefully

Other TestKing productsA) Offline Testing engineUse the offline Testing engine product topractice the questions in an exam environment.B) Study Guide (not available for all exams)Build a foundation of knowledge which will be useful also after passing the exam.

Latest VersionWe are constantly reviewing our products. New material is added and old material isrevised. Free updates are available for 90 days after the purchase. You should check yourmember zone at TestKing and update 3-4 days before the scheduled exam date.

Here is the procedure to get the latest version:

1.Go towww.testking.com2.Click on Member zone/Log in3.The latest versions of all purchased products are downloadable from here. Just click thelinks.For mostupdates,itisenough just to print the new questions at the end of the new version,not the whole document.

FeedbackIf you spot a possible improvement then please let us know. We always interested inimproving product quality.Feedback should be send to [email protected]. You should include the following:Exam number, version, page number, question number, and your login ID.

Our experts will answer your mail promptly.

CopyrightEach iPAD file contains a unique serial number associated with your particular name andcontact information for security purposes. So if we find out that a particular iPAD file isbeing distributed by you, TestKing reserves the right to take legal action against youaccording to the International Copyright Laws.

ExplanationsThis product does not include explanations at the moment. If you are interested inproviding explanations for this exam, please contact [email protected].

Page 3: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 3 -

QUESTION NO: 1

Given the code in the exhibit.

What is the result?

A. Compilation failsB. 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.

Answer: BExplanation:The following code can be tested: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);

Page 4: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 4 -

os.writeObject(f); os.close(); }catch(Exception exp){exp.printStackTrace();}}}class Tree{}

QUESTION NO: 2

Which code, inserted ay line 14, will allow this class to correctly serialized anddesterilize?

A. S. default ReadObject ( );B. This = s.defaultReadObject ( );C. y=s.default(); x=s.readInt();D. x=s.readInt(); y=s.readInt();

Page 5: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 5 -

Answer: D

QUESTION NO: 3 Given the exhibit.

What is the result?

A. 0B. 1C. 4D. Compilation failsE. An exception is thrown at runtime

Answer: D

QUESTION NO: 4 Given the exhibit:

The variable df is an object of type DateFormat that has been initialized in line 11.

What is the result if this code is run on December 14,2000?

A. The value of S is 14 - dic-2004B. The value of S is Dec 14, 2000

Page 6: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 6 -

C. An exception is thrown at runtimeD. Compilation fails because of an error in line 13.

Answer: D

QUESTION NO: 5 DRAG DROPThe doesFileExist method takes an array of directory names representing a pathfrom the root filesystem and a file name. The method returns true if the file exists,falst if does not.

Place the code fragments in position to complete this method.

Answer:Explanation:

Page 7: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 7 -

Example code:

import java.io.*;public class test2 {

public static void main(String []a){

test2 t = new test2();String []d = new String[2];d[0] = "C:";

System.out.println(t.doesFileExist(d,"test"));

}

public boolean doesFileExist(String []directories,Stringfilename){

String path = "";

Page 8: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 8 -

for(String dir: directories){

path = path +File.separator+dir;

//path = path.getSubdirectory(dir);}

System.out.println(path);

File file = new File(path,filename);

return file.exists();

}}

QUESTION NO: 6 DRAG DROPGiven:

System.out.printf("Pi is approximately %f and E is approximately %b", Math.PI,Math.E);

Place the values where they would appear in the output.

Answer:Explanation:

Page 9: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 9 -

QUESTION NO: 7 When comparing java. Io. BufferedWriter to java.io.FileWriter, which capabilityexist as a method in only one of the two?

A. closing the streamB. flushing the streamC. writing to the streamD. marking a location in the streamE. writing a line separator to the stream

Answer: E

QUESTION NO: 8 Given the exhibit:

Page 10: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 10 -

Which two code fragments, inserted independently at line 3, generate the output4247? (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) replace(1,3,).delete (2,5) insert (1, "24")

Answer: B,E

QUESTION NO: 9 Which three statements concerning the use of the java . io. Serializable interface aretrue? (choose three)

A. Object from classes that use aggregation cannot be serialized.B. An object serialized on one JVM can be successfully desterilized on a different JVM.C. The values in fields with the Volatile modifier will NOT survive serialization anddeserializationD. The values in field with the transient modifier will NOT survive serialization anddeserialization

Page 11: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 11 -

E. It is legal to serialize an object of a type that has a supertype that does NOT implementjava .io.Serialization

Answer: B,D,E

QUESTION NO: 10 Given the exhibit:

What is the result?

A. short LongB. SHORT LONGC. Compilation failsD. An exception is thrown at runtime

Answer: CExplanation: Two methods in a class can not have the same signature; it is violationof overloading methods.

Page 12: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 12 -

QUESTION NO: 11 Given the exhibit:

* D is valid , non-null Dateobject * df is a valid, non-null DateFormat object set to the current local

What outputs the current ; local's country name and the appropriate version of d'sdate?

A. Local loc = Locale.getLocal ( );System.out printIn (loc.getDisplayCountry ( )B. Local loc = Locale.getDefault ( );System.out printIn (loc.getDisplayCountry ( )+ " " +df. Format (d) );C. Local loc = Locale.getLocal ( );System.out printIn (loc.getDisplayCountry ( )+ " " +df. setDateFormat (d) ) ;D. Local loc = Locale.getDefault ( );System.out printIn (loc.getDisplayCountry ( )+ " " +df.seDateFormat (d) );

Answer: B

QUESTION NO: 12 Given the exhibit:

Page 13: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 13 -

What is the result?

A. Compilation fails.B. An exception is thrown at runtimeC. The code executes and prints " running"D. The code executes and prints "runningrunning"E. The code executes and prints "runningrunninigrunning

Answer: E

QUESTION NO: 13 Exhibit:

Page 14: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 14 -

Which two are possible results? (choose two)

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,

Answer: A,CExplanation:

Page 15: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 15 -

It is obvious that the output will be 8 digits, therefore, the options D,E are notcorrect. B can not be correct because the only way that it would be possible to havethe similar output order is when, the first process reads the x value and set the valueof current to 2 then print it but after that the processor perform content switchingto the second one. However in this case after second process finish it task, theprocessor perform content switching to the first process and it resumes, but it has atleast the value of 4 for x not 2. so the printing order on that case could be0,2,4,6,8,10,4,6.

QUESTION NO: 14 Given the exhibit:

Which statement is rue?

A. This code may throw an InterruptedExceptionB. This code may throw an IllegalStateExcepionC. This code may throw a TimeOutException after ten minutesD. This code will not compile unless "obj.wait ( ) \" is replaced with " (( Thread) obj).wait ( )"E. Reversing the order of obj.wait ( ) and obj. notify ( ) may vcause this method tocomplete normally

Answer: AExplanation: Wait() and notify() would throw InterruptedException, therefore, thecorrect answer is A not B.

Page 16: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 16 -

QUESTION NO: 15 Given the exhibit:

What can be a result?

A. Compilation failsB. An exception is thrown at runtimeC. The code executes and prints "StartedComplete"D. The code executes and prints "StartedComplete0123"E. The code executes and prints "Started0123Complete"

Answer: EExplanation:Join method will cause the current thread waits for the completion of executing thread.

Page 17: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 17 -

QUESTION NO: 16 Which two code fragments will execute the method doStuff ( ) in a separate thread?(choose two)

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 Runable ( ) { public void run ( ) { doStuff ( ); }}; run ( ) ;F. new Thread (new Runnable ( ) { public void run ( ) { doStuff ( ); }}),start ( );

Answer: D,F

QUESTION NO: 17 Which three will compile and run without exception? (choose three)

A. private synchronized object o;B. void go ( ) { synchronized ( ) { /* ocde 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 ( ) {synchronized (o) { /* code here */ }}

Page 18: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 18 -

Answer: C,E,F

QUESTION NO: 18 Exhibit:

Page 19: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 19 -

Page 20: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 20 -

What is the result?

A. The code will deadlockB. The code may run with no outputC. An exception is thrown at runtimeD. 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"

Answer: F

QUESTION NO: 19 Given the exhibit:

What is the result?A. Compilation failsB. An exception is thrown at runtimeC. The code executes normally and prints "sleep"D. The code executes normally, but nothing is printed.

Answer: C

QUESTION NO: 20Which two statements are true about has-a and is a relationships? (choose two)

A. Inheritance represents an is -a relationshipB. Inheritance represents a has-a relationshipC. Interfaces must be used when creating a has-a relationship

Page 21: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 21 -

D. Instance variables can be used when creating a has-a relationship

Answer: A,D

QUESTION NO: 21 Given the exhibit:

What can directly access and change the value of the variable name?

A. any classB. only the Target classC. any class in the testking packageD. any class that extends Target

Answer: C

QUESTION NO: 22 Which three statements are true? (choose three)

A. A final method in class x can be abstract if and only if X is abstractB. A protected method in class x can be overridden by any subclass of x.C. A private static method can be called only within other static methods in class X.D. A non-static public final method in class X can be overridden in any subclass of X.E. A public static method in class X can be called by a subclass of X without explicitlyreferencing the class x.

Page 22: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 22 -

F. A method with the same signature as a private final method in class X can beimplemented in a subclass of X.

Answer: B, E, FExplanation:BEF is correct, although the final method can not be overridden in its subclasses but aprivate final method can not be seen in its sub class therefore it is not overriding itsparent's method. C is not correct because the static member can be called in other nonstatic methods; however in a static method non-static members could not be used.

QUESTION NO: 23 DRAG DROPPlace the Types in one of the Type columns, and the Relationships in theRelationship column, to define appropriate has-a and is-a relationships.

Answer:Explanation:

Page 23: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 23 -

QUESTION NO: 24 DRAG DROPReplace two of the Modifiers that appear in the Single class to make the codecompile.Note: Three modifiers will not be used and four modifiers in the code will remainunchanged.

Page 24: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 24 -

Answer:Explanation:

Page 25: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 25 -

The last two boxes are protected and static. The first one is protected because it should bereusable in SingleSub class. The last box should be static because it will be used in astatic method, therefore the method should be static.

QUESTION NO: 25 Exhibit:

What is the result?

A. Value is : 8

Page 26: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 26 -

B. Compilation fails.C. Value is : 12D. Value is ; -12E. The code runs with no outputF. An exception is thrown at runtime.

Answer: A

QUESTION NO: 26 Given the exhibit:

Which statement is true?

A. The class is fully encapsulatedB. The code demonstrates polymorphism.C. The ownerName variable breaks encapsulationD. The CardID and limit variables break polymorphismE. The setCardInformation method breaks encapsulation

Page 27: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 27 -

Answer: C

QUESTION NO: 27 Given the exhibit:

What is the result?

A. peepB. barkC. meowD. Compilation fails.E. An exception is thrown at runtime

Answer: EExplanation:It firstly instantiates a Dog object and refer it animal, but when it tries to cast an animalwhich is originally a dog to a cat, it will rise IllegalCastException which is aRuntimeException

Page 28: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 28 -

QUESTION NO: 28 Exhibit:

What two must the programmer do to oerrect the compilation errors?

A. insert a call to this ( ) in the Car CONSTRUCTORB. insert a call to this ( ) in the MeGo constructorC. insert a call to super ( ) in the MeGo constructorD. insert a call to super (vin) in the MeGo constructorE. change the wheel Count variable in CAR TO PROTECTEDF. CHANGE LINE 3 IN THE MeGo class to super wheel Count =3;

Answer: D,E

Page 29: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 29 -

QUESTION NO: 29 Given the exhibit:

What three code fragments inserted individually at line 15, make use ofpolymorphism? (choose three)

A. public void add (C c) { c.getValue ( ); }B. public void add (B b) { b.getValue ( ); }C. public void add (A a) { a.getValue ( ); }D. public void add (A a, B b) { a.getValue ( ); }E. public void add (C c1 C c2) { c1.getValue ( ); }

Answer: B,C,D

QUESTION NO: 30 Given the exhibit:

Page 30: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 30 -

Which statement should be placed at line 14 to suggest that the virtual machineexpend effort toward recycling the memory used by the object testking?

A. System.gc ( )B. Runtime. Gc ( )C. System.freeMemory ( )D. Runtime.getRuntime ( ) growHeap ( )E. Runtime.getRuntime ( ) free Memory ( )

Answer: A

QUESTION NO: 31 Exhibit:

Page 31: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 31 -

What is the output of the program shown in the exhibit?

A. 300.100.100.100.100B. 300.300.100.100.100C. 300.300.300.100.100D. 300.300.300.300.100

Answer: B

Page 32: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 32 -

QUESTION NO: 32 A developer is creating a class Book, that needs to acces class Paper. The Paperclass is deployed in a JAR named myLib.jar.Which three, taken independently, will allow the developer to use the Paper classwhile compiling the Book class? (choose three)A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jarB. The JAR file is located at $/JAVA_HOME/jre/lib/ext/myLib.jar..C. The JAR file is located at /foo/myLib.jar and a classpath environment variable is setthat includes /foo/myLib.jar/Paper,Class.D. The JAR file is located at /foo/myLib.jar and a classpath environment variable is setthat includes /foo/myLib.jar.E. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac-cp /foo/myLib.jar/Paper Book.java.F. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d/foo/myLib.jar Book.java.G. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac-classpath /foo/myLib.jar Book.java

Answer: B,D,G

QUESTION NO: 33 Given the exhibit:

Page 33: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 33 -

Which statement is true about the object referenced by snoog, smooch and boochimmediately after line 23 executes?

A. None of these objects are eligible for garbage collectionB. Only the object referenced by booch is eligible for garbage collectionC. Only the pbject referenced by snoog is eligible for garbage colletionD. Only the object referenced by smooch is eligible for garbage collectionE. The objects referenced by smooch and booch are eligible for garbage collection

Answer: E

QUESTION NO: 34 Given the exhibit:

Page 34: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 34 -

and the command line invocation

java testking5 a b c

what is the result?A. a bB. b cC. a b cd. Compilation failsC. An exception is thrown at runtime

Answer: B

QUESTION NO: 35 Given the exhibit:

Page 35: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 35 -

What is the result?

A. r, t, tB. r, e, o,C. Compilation failsD. An exception is thrown at runtime

Answer: C

QUESTION NO: 36 Given the exhibit:

Page 36: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 36 -

and the command line:

java - Drop.custom = gobstopper TestKing

Which two, placed on line 13, will produce the output gobstopper? (choose two)

A. System.load ("prop.custom");B. System.getenv ("prop.custom");C. System.property ("prop.custom");D. System.getProperty("prop.custom");E. System.getProperties ( ).getProperty ("prop.custom");

Answer: D,EExplanation: It should be java -Dprop.custom=gobstopper TestKing

QUESTION NO: 37 Given classes defined in two different files:

What is required at line 5 in class TestKingApp to use the process method of Bit Utils?

Page 37: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 37 -

A. Process (bytes);B. BitUtils.process (bytes);C. Util.BitUtils.process (bytes);D. TestKingApp cannot use methods in BitUtilsE. Import util.BitUtils.*; process (bytes);

Answer: C

QUESTION NO: 38 Exhibit:

What is the outcome of the code?

Page 38: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 38 -

A. Compilation fails.B. GobstopperFizzyliftingC. GobstopperScremdiddlyumptiousD. ScrumdiddlyumptiousFizzyliftingE. ScrumiddlyumptiousScrumdiddlyumptious

Answer: B

QUESTION NO: 39 Given classes defined in two different files

What is required at line 5 in class TestKingApplication to use the process method ofBitUtils?

A. PROCESS (BYTES);B. BitUtils.process(bytes);C. App.BitUtils.process (bytes)

Page 39: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 39 -

D. Util.BitUtils. process (bytes)E. Import util.BitUtils.*; process (bytes);F. TestKingApplication cannot use the process method in BitUtils.

Answer: F

QUESTION NO: 40 DRAG DROP

The image represents a complete package structure for a set of classes: "com" is thebeginning of the fully-qualified package name for all classes.

Give this package structure, insert the code needed to make the Car class compileand runt successfully.All three placeholds must be filled. If fewer than three statement are needed, use the"// blank" options.

Page 40: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 40 -

Answer:Explanation:

A class can NOT be a member of two packages therefore the correct answer is

Page 41: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 41 -

Package com.bar;Import com.foor.bar.*;//for Dog;Import com.foo.bar.blatz.*; //for Book class

QUESTION NO: 41 Given the exhibit:

What is the result when this ode executed?

A. 1B. 3C. 123D. 321E. The code runs with no output

Answer: C

QUESTION NO: 42 DRAG DROPPlace the code fragments in position to complete the Displayable interface.

Page 42: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 42 -

Answer:Explanation:

Page 43: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 43 -

QUESTION NO: 43 Given the exhibit:

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

A. Direction d = NORTHB. TestKing.Direction d = NORTHC. Direction d = Direction.NORTHD. TestKing.Direction d = TestKing Direction. NORTH

Answer: D

QUESTION NO: 44 Exhibit:

Page 44: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 44 -

Which three statements are true? (Choose three)

A. Compilation failsB. The code compiles and the output is 2C. 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 be2.F. If line 24,25 and 26 were removed, the code would compile and the output would be 1.

Answer: B,E,F

Page 45: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 45 -

QUESTION NO: 45 DRAG DROPAdd methods to the Beta class to make it compile correctly.

Answer:Explanation:

Page 46: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 46 -

QUESTION NO: 46

Given the exhibit:

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

Page 47: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 47 -

A. 5B. 10C. 12D. 17E. 24

Answer: B

QUESTION NO: 47 Given the exhibit:

Which two methods, inserted individually, correctly complete the TestKing3 class?(choose two)

A. public void fooo ( ) { }B. public int foo ( ) {return 3: }C. public TestKing2 foo ( ) {return this;}D. public TestKing1 foo ( ) {return this}

Answer: C,D

QUESTION NO: 48 Exhibit:

Page 48: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 48 -

What is the result?

A. snootchy 420 third second firstB. snootchy 420 first second thirdC. first second third snootchy 420D. third second first snootchy 420E. thirds first second snootchy 420F. first second first third snootchy 420

Answer: D

Page 49: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 49 -

QUESTION NO: 49 Given the exhibit:

What is the result?

A. 1 2 3B. Compiltion fails because of an error in line 12.C. Compilation fails because of an error in line 13D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime

Answer: A

QUESTION NO: 50 A Java Bean component has the following field:

11. PRIVATE BOOLEAN ENABLED:

Which two pairs of method declarations follow the JavaBean standard for accessingthis fields? (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 void setEnabled ( Boolean enabled)public Boolean getEnabled ( )

Page 50: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 50 -

Answer: A,C

QUESTION NO: 51 Given the exhibit:

Which two statements are true? (choose two)

A. TestKing.beta ( ) is a valid invocation of beta ( )B. TestKing.alpha ( ) is a valid invocation of alpha ( )C. Method beta ( ) can directly call method alpha ( )D. Method alpha ( ) can directly call method beta ( )

Answer: B,C

QUESTION NO: 52 Given the exhibit:

Page 51: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 51 -

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 extend 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: B, E

Page 52: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 52 -

QUESTION NO: 53 Given the exhibit:

What is the result

A. BB. The code exception is thrown at runtimeC. The cod run with no output.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 NO: 54 Given the exhibit:

Page 53: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 53 -

What is the result if NullPointerException occurs on line 34?

A. cB. aC. abD. acE. bcF. abc

Answer: D

QUESTION NO: 55 Given the exhibit:

Page 54: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 54 -

Which exception or error will be thrown when a programmer attempts to run thiscode?

A. java.lang.StackOverflowErrorB. java.lang.IllegalStateExceptionC. java.lang.ExceptionInInitoatializerErrorD. java.lang.ArrayIndexOutOfBoundsException

Answer: C

QUESTION NO: 56 Exhibit:

Page 55: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 55 -

Which two statements are truee if a NullPointerException is thrown on line 3 ofclass C? (choose two)

A. The application will crash.B. The code on line 29 will be executedC. 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: B,E

QUESTION NO: 57 Given the exhibit:

What is the result?

A. 0B. 10C. 12D. Line 29 will never be reached.

Page 56: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 56 -

Answer: C

QUESTION NO: 58 Given the exhibit:

What is the result?

A. The value "4" is printed at the command lineB. 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 NO: 59 Given the exhibit:

Page 57: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 57 -

What is the result?

A. 3, 2, 1,B. 1, 2, 3,C. Compilation failsD. The code runs with no outputE. An exception is thrown at runtime

Answer: C

QUESTION NO: 60 Given the exhibit:

Page 58: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 58 -

What is the result when method testIfA is invoked?

A. TrueB. Not trueC. An exception is thrown at runtimeD. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19.

Answer: A

QUESTION NO: 61 GIVEN THE EXHIBIT:

Page 59: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 59 -

Which statement is true?A. All of the assert statements are used appropriately.B. Only the assert statement on line 31 is used appropriatelyC. The assert statements on lines 29 and 31 are used appropriatelyD. The assert statements on lines 26 and 29 are used appropriatelyE. The assert statements on lines 29 and 33 are used appropriatelyF. The assert statements on lines 29 ,31and 33 are used appropriatelyG. The assert statements on lines 26,29 and 31 are used appropriately

Answer: C

QUESTION NO: 62 GIVEN THE EXHIBIT:

Page 60: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 60 -

What is the result?

A. nullB. zeroC. someD. Compilation failsE. An exception is thrown at runtime

Answer: D

QUESTION NO: 63 Given the exhibit:

Page 61: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 61 -

What is the result?

A. testB. ExceptionC. Compilation failsD. NullPointerException

Answer: C

QUESTION NO: 64 Given the exhibit:

Page 62: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 62 -

What is the result?

A. Compilation failsB. aAaA aAa AAaa AaAC. AAaa AaA aAa aAaAD. AaA AAaa aAaA aAaE. aAa AaA aAaA AAaaF. An exception is thrown at runtime

Answer: C

QUESTION NO: 65 Given the exhibit:

Page 63: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 63 -

What is the result?A. 0B. 1C. 2D. 3E. 4F. Compilation fails.G. An exception is thrown at runtime

Answer: D

QUESTION NO: 66 Given a pre-generics implementation of a method:

Page 64: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 64 -

Which three changes must be made to the method sum to use generics? (choosethree)

A. remove line 14B. replace line 14 with "int I = iter.next ( ); "C. replace line 13 with "for ( int I : intList ) {"D. replace line 13 with " for (Iterator iter : intLiswt ) "E. replace the method declaration with "sum (List<int> intList)"F. replace the method declaration with "sum ( List<Integer> intList)"

Answer: A, C, F

QUESTION NO: 67 Given the exhibit:

Page 65: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 65 -

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 ClassCastExceptation occurs in line 29.D. A ClassCastExceptation occurs in line 31.E. The value of all four object prints in natural order.

Answer: C

QUESTION NO: 68 DRAG DROPPlace the code into position to create a class that maps from Strings to integervalues.The result of execution must be [one]. Some options may be used more than once.

Page 66: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 66 -

Answer:Explanation:

Page 67: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 67 -

Example code:import java.util.*;public class NumberNames { private HashMap <String,Integer> map = new HashMap<String,Integer>(); public void put(String name,int value){ map.put(name,value); } public Set<String> getNames(){ return map.keySet(); }}

QUESTION NO: 69 DRAG DROPPlace a result onto each motho call to indicate what would happen if the method callwere inserted at line 9. Note: Results can be used more than once.

Page 68: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 68 -

Answer:Explanation:

Page 69: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 69 -

QUESTION NO: 70 Given the exhibit:

What is the result?

A. apple:apple

Page 70: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 70 -

B. carrot:appleC. apple:bananaD. banana:appleE. carrot:carrotF. carrot:banana

Answer: C

QUESTION NO: 71 Given :

A programmer is developing a class Key, that will be used as a key in a standardjava.util.HashMap.

Which two methods should be overridden to assure that key works correctly as akey? (choose two)

A. public int hashCode ( )B. public Boolean equals (Key k)C. public int compareTo (object oD. public Boolean equals (object o)

Answer: A,D

QUESTION NO: 72 Given the exhibit:

Page 71: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 71 -

Which two, inserted at line 11 will allow the code to compile? (Choose Two)

A. public class MinMax< ? > {B. public class MinMax < ? extends Number> {C. public class MinMax <N extends Object> {D. public class MinMax <N extends Number > {E. public class MinMax < ? extends Object > {F. public class MinMax < N extends Integer > {

Answer: D,F

QUESTION NO: 73 Given the exhibit:

enum Example { ONE, TWO, THREE }

Which statement is true?

A. The expressions (ONE = = ONE) and ONE.equals (ONE) are both guaranteed to betrue.B. The expression (ONE < TWO ) is guaranteed to be true and ONE.compareTo (TWO)is guaranteed to be less than one.

Page 72: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 72 -

C. The Example values cannot be used in a raw java.util.HasMap.; instead, theprogrammer must use a java.util.EnumMap.D. The Example values can be used in a java.util.SortedSet, but the set will NOT besorted because enumerated Type do NOT IMPLEMENT JAVA.LANG.Comparable.

Answer: A

QUESTION NO: 74Given:

Which line of code marks the earliest point that an object referenced by intObjbecomes a candidate for garbage collection?

A. Line 16B. Line 17C. Line 18D. Line 19E. The object is NOT a candidate for garbage collection.

Answer: D

QUESTION NO: 75Given:

Page 73: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 73 -

andthe command line invocation:javaYippee2 a b cWhat is the result?

A. a bB. b cC. a b cD. Compilation fails.E. An exception is thrown at runtime.

Answer: B

QUESTION NO: 76A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wantsto execute the main method of Poker on a UNIX system using the command:Java games.cards.PokerWhat allows the user to do this?

A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/javaB. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include

/stuff/java/*.jarC. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include

/stuff/java/Poker.jarD. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include

/stuff/javaE. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include

/stuff/java/*.jarF. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include

/stuff/java/Poker.jar

Page 74: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 74 -

Answer: C

QUESTION NO: 77Exhibit:

Which three code fragments, added individually at line 29, produce the output 100?(Choose three.)

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

Page 75: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 75 -

Answer: B, C, F

QUESTION NO: 78Given a class Repetition:

And given another class Demo:

Which code should be inserted at line 1 of Demo.java to compile and run Demo toprint "pizzapizza"

A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition.*;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;

Answer: F

Page 76: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 76 -

QUESTION NO: 79Given:

And the invocation:

What is the result?

A. An exception is thrown at runtime.B. "String is empty" is printed to output.C. Compilation fails because of an error in line 12.D. "String is not empty" is printed to output.

Answer: A

QUESTION NO: 80Exhibit:

Page 77: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 77 -

Given the fully-qualified class names:

com.foo.bar.Dogcom.foo.bar.blatz.Bookcom.bar.Carcom.bar.blatz.Sun

Which graph represents the correct directory structure for a JAR file from whichthose classes can be used by the compiler and JVM?

A. Jar AB. Jar B

Page 78: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 78 -

C. Jar CD. Jar DE. Jar E

Answer: A

QUESTION NO: 81Given:

and two separate command line invocations:

java Yippeejava Yippee 1 2 3 4

What is the result?

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

Answer: B

Page 79: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 79 -

QUESTION NO: 82Given:

What is the result?

A. Compilation failsB. An exception is thrown at runtimeC. doStuff x = 6 main x = 6D. doStuff x = 5 main x = 5E. doStuff x = 5 main x = 6F. doStuff x = 6 main x = 5

Answer: DExplanation:The value of x in the main method would not change because it pass the variable x by itsvalue not by its reference to the doStuff method.

QUESTION NO: 83Given:

Page 80: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 80 -

When the doSomething method is called, after which line does the Object created inline 5 bbecome available for garbage collection?

A. Line 5B. Line 6C. Line 7D. Line 8E. Line 9F. Line 10

Answer: CExplanation:The correct is line 7 because afterwards there is no other reference referring to that object.Therefore, it is useless.

QUESTION NO: 84Given:

Page 81: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 81 -

What is the result?

A. ExceptionB. A, B, ExceptionC. 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 NO: 85Given:

Page 82: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 82 -

What is the result?

A. harrierB. shepherdC. retrieverD. Compilation failsE. retriever harrierF. An exception is thrown at runtime.

Answer: DExplanation: Compilation fails is correct, because there is no "case default" in java,therefore it will rise a compilation error with this message:illegal start of expression

QUESTION NO: 86Given:

What is the result?

A. A, B, CB. B, C, AC. Compilation failsD. The code runs with no outputE. An exception is thrown at runtime

Page 83: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 83 -

Answer: B

QUESTION NO: 87Given:

What is the result?

A. endB. Compilation failsC. exception endD. exception test endE. A Throwable is thrown by mainF. An Exception is thrown by main

Answer: E

QUESTION NO: 88Given:

Page 84: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 84 -

What is the result? Select all that apply.

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: BExplanation: Only B can be true, C can not e true otherwise the code would notcompile. Regarding to E it is not guarantee not to throw exception.

QUESTION NO: 89Given:

Page 85: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 85 -

What is the result?

A. Compilation failsB. 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 NO: 90Given:

Which code, inserted at line 16 will cause a java.lang.ClassCastException?

Page 86: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 86 -

A. Alpha a = x;B. Foo f = (Delta)x;C. Foo f = (Alpha)x;D. Beta b = (Beta)(Alpha)x;

Answer: B

QUESTION NO: 91Given a method that must ensure that its parameter is not null:

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 NO: 92 DRAG DROPPlace the correct Code in the Code Sample to achieve the expected results.

Page 87: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 87 -

Expected results:Output: 1 2 4 8 16 32

Code Sample

Answer:

Page 88: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 88 -

QUESTION NO: 93Given:

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

A. java testB. java -ea testC. java test file1D. java -ea test file1E. java -ea test file1 file2F. java -ea:test test file1

Answer: B, E

QUESTION NO: 94Given:

Which statement is true if a ResourceException is thrown on line 86?

Page 89: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 89 -

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 NO: 95Assuming that the serializeBanana() and the deserializeBanana() methods will correctlyuse Java serialization and given:

What is the result?

A. restore 400B. restore 403C. restore 453D. Compilation fails.E. An exception is thrown at runtime.

Answer: CExplanation:As an example the following code can be used.

Page 90: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 90 -

import java.io.*;public class Q95{public static void main(String[] args){try{Banana b=new Banana(); Banana b2=new Banana();File objectFile=new File("banana.ser");FileOutputStream fo=new FileOutputStream(objectFile);ObjectOutputStream ow=new ObjectOutputStream(fo);ow.writeObject(b);ow.close();FileInputStream fi=new FileInputStream(objectFile);ObjectInputStream or=new ObjectInputStream(fi);b2=(Banana)or.readObject();or.close();System.out.println("restore:"+b2.yellow+b2.juice+b2.good);}catch(Exception exp){exp.printStackTrace();}finally{//objectFile=null;//fo=null;//fi=null;//ow=null;//or=null;}

}}class Food implements Serializable{int good=3;}class Fruit extends Food{ int juice=5;}class Banana extends Fruit{ int yellow=4;}

QUESTION NO: 96Given:

What is the result?

Page 91: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 91 -

A. Compilation failsB. Pi is approximately 3.C. Pi is approximately 3.141593.D. An exception is thrown at runtime.

Answer: D

QUESTION NO: 97Given:

What is the result?

A. int LongB. Short LongC. Compilation failsD. An exception is thrown at runtime.

Answer: A

QUESTION NO: 98 DRAG DROPChain these constructors to create objects to read from a file named "in" and towrite to a file named "out".

Page 92: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 92 -

Answer:Explanation:

Sample code:import java.io.*;public class Files {public static void main(String []args){try{BufferedReader reader = new BufferedReader(newFileReader("in"));PrintWriter writer = new PrintWriter(new BufferedWriter(newFileWriter("out"))); } catch (Exception ex){System.out.println("Exception!!"); } }}

Page 93: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 93 -

QUESTION NO: 99 DRAG DROPPlace the code fragments into position to use a BufferedReader to read in an entiretext file.

Answer:Explanation:

Page 94: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 94 -

QUESTION NO: 100Given this method in a class:

Which statement is true?

A. This code is NOT thread-safe.

Page 95: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 95 -

B. The programmer can replace StringBuffer with StringBuilder with no other changes.C. This code will perform poorly. For better performance, the code should be rewritten:

return "<" + this.name + ">";D. This code will perform well and converting the code to use StringBuilder will not

enhance the performance.

Answer: B

QUESTION NO: 101Given:

What creates the appropriate DateFormat object and adds a day to the Date object?

A. 35. Dateformat df = DateFormat.getDateFormat(); 42. d.setTime ( (60 * 60 * 24) + d.getTime());

B. 35. Dateformat df = DateFormat.getDateInstance(); 42. d.setTime ( (1000 * 60 * 60 * 24) + d.getTime());

C. 35. Dateformat df = DateFormat.getDateFormat(); 42. d.setLocalTime ( (1000 * 60 * 60 * 24) + d.getLocalTime());

D. 35. Dateformat df = DateFormat.getDateInstance(); 42. d.setLocalTime ( (60 * 60 * 24) + d.getLocalTime());

Answer: B

Page 96: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 96 -

QUESTION NO: 102Given:

Which two statements are true about the result if the locale is Locale.US? (Choosetwo.)

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.

Answer: C, F

QUESTION NO: 103 DRAG DROPPlace the correct description of the compiler output on the code fragment to beinserted at line 4 and 5. The same compiler output may be used more than once.

Page 97: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 97 -

Answer:

Page 98: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 98 -

Explanation:

QUESTION NO: 104Given:

Page 99: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 99 -

Which three will compile successfully? (Choose three.)

A. Object o = Old.get0(new LinkedList());B. Object o = Old.get0(new LinkedList<?>());C. String s = Old.get0(new LinkedList<String>());D. Object o = Old.get0(new LinkedList<Object>());E. String s = (String)Old.get0(new LinkedList<String>());

Answer: A, D, E

QUESTION NO: 105Exhibit:

Which statement is true about the set variable on line 12?

Page 100: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 100 -

A. The set variable contains all six elements from the coll collection, and the order isguaranteed to be preserved.

B. The set variable contains only three elements from the coll collection, and the order isguaranteed to be preserved.

C. The set variable contains all six elements from the coll collection, but the order isNOT guaranteed to be preserved.

D. The set variable contains only three elements from the coll collection, but the order isNOT guaranteed to be preserved.

Answer: D

QUESTION NO: 106Given:

What is the appropriated definition of the hashCode method in class Person?

A. return super.hashCode();B. return name.hashCode() + age * 7;C. return name.hashCode() + comment.hashCode() / 2;D. return name.hashCode() + comment.hashCode() / 2 - age * 3;

Answer: BExplanation:

Page 101: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 101 -

hashCode method of an object should return a unique key for that object. Usually, thevalue of hashCode is dependent to the content of object. ( as long as the content will beconsidered for equality of two objects). By looking to the consisting elements it would beobvious that the three variable should be counted in hashCode method, however becausethe equality of two object is measured by two attributes out of three therefore, thehashCode method also should be based on those two attributes. Comment can not be apart of hashCode, cause by the definition of equal method two objects with differentcomment attribute and same other two attributes are considered equal.

QUESTION NO: 107Given:

Which statement is true?

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 java.util. Set collection, the equals method in line 4

will prevent duplicates.

Answer: AExplanation:This question has two potential correct answers. Firstly A is correct cause equals methosshould override equals(Object obj) of Object class. Secondly, in the hash data structure, iftwo equals objects have to have same key therefore, their hashCode object also shouldreturn the same value. Therefore C could be correct!

Page 102: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 102 -

QUESTION NO: 108Given:

Which code, inserted at line 4, guarantees that this program will output [1, 2]?

A. Set set = new TreeSet();B. Set set = new HashSet();C. Set set = new SortedSet();D. List set = new SortedList();E. Set set = new LinkedHashSet();

Answer: A

QUESTION NO: 109Given:

What, inserted at line 39, will sort the keys in the props HashMap?

Page 103: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 103 -

A. Array.sort(s);B. s = new TreeSet(s);C. Collections.sort(s);D. s = new SortedSet(s);

Answer: B

QUESTION NO: 110 DRAG DROPPlace code into the class so that it compiles and generates the output answer=42.Note: Code options may be used more than once.

Answer:Explanation:

Page 104: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 104 -

Sample code:public class Q110{public static void main(String[] args){ Gen<String> str=new Gen<String>("answer"); Gen<Integer> intg=new Gen<Integer>(3); System.out.println(str.getObject()+"="+intg.getObject());}}class Gen<T>{private T object;public Gen(T object){ this.object=object;}public T getObject(){ return object;}}

QUESTION NO: 111 DRAG DROPGiven:

Page 105: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 105 -

Place the Compilation Results on each code statement to indicate whether or notthat code will compile if inserted into the takeList() method.

Answer:Explanation:

Page 106: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 106 -

list.add("Foo"); Compilation fails/ the passed list<? extends String> will be considered as final, nomodification to list is allowed unless it has been defined as List<? super String>

list=new ArrayList<String>();/ Compilation succeedslist=new ArrayList<Object>();/ Compilation fails it should be ArrayList<String>String s=list.get(0);/Compilation succeedsObject o=list;/ Compilation succeeds

QUESTION NO: 112Which two code fragments will execute the method doStuff() in a separate thread?(Choose two.)

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

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

Page 107: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 107 -

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

Answer: D, FExplanation:Not E: The reason these two answers are correct not E, Is because D,E will start a Threadbut in E it will execute a method which execution of this method should be finished to beable to run the next statement.

QUESTION NO: 113Given:

Page 108: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 108 -

Which to can be results? (Choose two.)

A. java.lang.RuntimeException: ProblemB. run.

java.lang.RuntimeException: ProblemC. End of method.

java.lang.RuntimeException: ProblemD. End of method.

run. java.lang.RuntimeException: Problem

E. run. java.lang.RuntimeException: Problem End of method

Answer: D, E

QUESTION NO: 114Given:

Which three changes should be made to adapt this class to be used safely bymultiple threads? (Choose three.)

A. declare reset() using the synchronized keywordB. declare getName() using the synchronized keywordC. declare getCount() using the synchronized keywordD. declare the constructor using the synchronized keywordE. declare increment() using the synchronized keyword

Page 109: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 109 -

Answer: A, C, EExplanation:Sample code:public class Q114{public static void main(String[] args){ Product product=new Product("SCJP"); Thread producer=new Thread(new Producer(product)); Thread consumer=new Thread(new Consumer(product)); consumer.start(); producer.start();}}

class Producer implements Runnable{ private Product product; public Producer(Product product){this.product=product;} public void run(){ while(product.getCount()<100){ product.increment(); } System.out.println("Total produced produced:"+ product.getItemProduced()); }}class Consumer implements Runnable{ private Product product; public Consumer(Product product){this.product=product;} public void run(){ while(product.getCount()<100){ if(product.getCount()<0) {} product.decrement();}

}

}class Product{private final String name;private int count, itemProduced=0;

public Product(String name){ this.name=name; count=0;}public String getName(){return name;}public synchronized void increment(){ count++; itemProduced++; System.out.println("A product has been produced! ");

Page 110: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 110 -

notify(); }public synchronized void decrement(){ if(count<0){ try{ System.out.println("Consumer waiting"); wait();}catch(InterruptedExceptionexp){exp.printStackTrace();} }else{ count--; System.out.println("A product has been consumed!"); }}public synchronized void reset(){ count=0;}public int getCount(){ return count;}public int getItemProduced(){return itemProduced;}}

QUESTION NO: 115Given:

Which statement is true?

A. Compilation failsB. An exception is thrown at runtime.C. Synchronizing the run() method would make the class thread-safe.D. The data in variable "x" are protected from concurrent access problems.E. Declaring the doThings() method as static would make the class thread-safe.F. Wrapping the statements within doThings() in a synchronized(new Object()) { } block

would make the class thread-safe.

Page 111: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 111 -

Answer: EExplanation:The class is NOT thread safe.

Reason : If two instances of the same class are created, it will create two different threads. Now, if boththreads are calling this method doThings() which is synchronized, they are getting lock on their respectiveobject and not on the "Class object".And a static variable is being shared between both the instances.To make this thread safe, a lock on the .Class instance should be acquired because only one .class instanceexists.

Or You can also make doThings as a static synchronized method.

QUESTION NO: 116Given:

What statement is true?

A. This code may throw an InterruptedException.B. This code may throw an IllegalStateException.C. This code may throw a TimeoutException after ten minutes.D. This code will not compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".E. A call to notify() or notifyAll() from another thread may cause this method to complete

normally.

Answer: A

Page 112: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 112 -

Explanation: This code would not be compiled because the obj.wait() would causeInterruptedException, NOT IllegalStateException, if the InterruptedExceptioncaught it would cause IllegalMonitorStateException.

QUESTION NO: 117Given:

Which two statements 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: B, C

QUESTION NO: 118 DRAG DROPPlace the Output Options in the Actual Output Sequence to indicate the output fromthis code:

Page 113: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 113 -

Answer:Explanation:

Page 114: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 114 -

This order of output is because of nature overriding happened in the above classes. Ascan be seen in the code snippet class Beta has not overridden foo() method of class Alpha,as a result when variable a which its type is Alpha being invoked for its foo firstly wouldlook at Beta (because a instantiated from Beta) but it couldn't find the overridden methodtherefore will refer to its own method of foo(). However, the bar() method of Class Betahas overridden the Alpha's bar method therefore, it will be run instead alpha's bar methodfor a.bar(). Additionally, when variable b is instantiated from casting a to b (which isoriginally a Beta class instance), will run Beta's methods.

QUESTION NO: 119Given:

What is the result?

A. 0 . 0B. 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 NO: 120

Page 115: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 115 -

Given:

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. import com.sun.scjp; public class TerraCarta { public double halfway() { return DIAMETER/2.0;}}

Answer: A, C

QUESTION NO: 121Given:

Page 116: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 116 -

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

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

Answer: B

QUESTION NO: 122Given:

Which statement is true?

A. The code will compile without changes.

Page 117: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 117 -

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: DExplanation: This code will generate compilation error, because when in the Plantclass there is a constructor with an argument compiler will not generate the defaultconstructor which is public Plant(){;}, it will make problem in the sub classes of thisclass who doesn't have a constructor and compiler will make a default constructorfor them which will call super(); in it. Therefore adding an empty constructor inPlant will avoid that error.

QUESTION NO: 123Given:

Which two code fragments, inserted independently at line 12, will allow the class tocompile? (Choose two.)

A. foreach( x ) System.out.println(z);B. for( int z : x ) System.out.println(z);C. while( x.hashNext() ) System.out.println( x.next() );D. for( int i=0; i < x.length; i++ ) System.out.println(x[i]);

Answer: B, D

QUESTION NO: 124Exhibit:

Page 118: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 118 -

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: CExplanation: The execute method in class C, is trying to override the B's execute()method in a wrong way, to correct it the execute method signature in class C, shouldchange to public String execute().

Page 119: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 119 -

QUESTION NO: 125 DRAG DROPPlace the lines in the correct order to complete the enum.

enumElement {

Answer:Explanation:

Page 120: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 120 -

Code:enum enumElement { EARTH,WIND,FIRE { public String info(){ return "Hot"; } } }; public String info(){ return "element"; }

QUESTION NO: 126 DRAG DROPPlace the code elements in order so that the resulting Java source file will compilecorrectly, resulting in a class called com.sun.cert.AddressBook.

Page 121: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 121 -

Answer:Explanation:

Page 122: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 122 -

QUESTION NO: 127Which two classes correctly implement both the java.lang.Runnable and thejava.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*/}

Page 123: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 123 -

}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: C, D

QUESTION NO: 128Given:

Page 124: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 124 -

Which statement is true?

A. 420 is the outputB. 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.

Answer: AExplanation: This code will make compilation error, because the constructor ofExtendedA should have been defined as protected or public at least.However, the other options could not be correct, because a constructor can be defined asprivate or protected. Therefore, none of the options could be true.

QUESTION NO: 129Given:

What is the result?

A. foofoofoofoofooB. foobarfoobarbarC. foobarfoofoofoo

Page 125: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 125 -

D. foobarfoobarfooE. barbarbarbarbarF. foofoofoobarbarG. foofoofoobarfoo

Answer: D

QUESTION NO: 130Which two statements are true about has-a and is-a relationships? (Choose two.)

A. Inheritance represents an is-a relationship.B. Inheritance represents an has-a relationship.C. Interfaces must be use when creating a has-a relationship.D. Instance variables can be used when creating a has-a relationship.

Answer: A, D

QUESTION NO: 131Given:

Which statement is true about the class of an object that can reference the variablebase?

A. It can be any class.B. No class has access to base.C. The class must belong to the geometry package.D. The class must be a subclass of the class Hypotenuse.

Page 126: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 126 -

Answer: C

QUESTION NO: 132 DRAG DROPGiven:

Place the names "A" and "B" in the following output.

Page 127: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 127 -

Answer:Explanation:

QUESTION NO: 133Given:

What is the result?

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.

Page 128: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 128 -

Answer: F

QUESTION NO: 134Which two statements are true? (Choose two.)

A. An encapsulation, public class promotes re-use.B. Classes that share the same interface are always tightly encapsulated.C. An encapsulated class allows subclasses to overload methods, but does NOT allow

overriding methods.D. An encapsulated class allows programmer to change an implementation without

affecting outside code.

Answer: A, D

QUESTION NO: 135 DRAG DROPPlace the Relations on their corresponding Implementation Structures.Note: Not all Implementation Structres will be used.

Page 129: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 129 -

Answer:Explanation:

Page 130: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 130 -

Car is a Vehicle and Car is a CollectableThis statement indicates multi inheritance which is not supported by Java. Therefore,class A extends B,C{} is not correct, however, Java came across multi inheritance byusing interfaces. In this was Vehicle is represented as an interface and being Collectableis also presented as an interface, therefore class A implements B,C{} is the propermappingCar has a Steering wheelClass A{B b;}

Page 131: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 131 -

Car has Wheels

Class A{List<B> b;}

Mini is a Car & Car is an Object are both expressing an inheritance relation.Class A extends B{}

QUESTION NO: 136Given:

And:

What is the result?

A. HelloB. Hello WorldC. Compilation fails.D. Hello World 5E. The code runs with no output.F. An exception is thrown at runtime.

Page 132: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 132 -

Answer: CExplanation:In the second constructor, Hello method firstly should be called like this(); and also itshould be called as the first statement of the method likepublic Hello(int value){this();this.value=value;title="Hello";}

QUESTION NO: 137Given:

Which two, independently, will allow Sub to compile? (Choose two.)

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

Page 133: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 133 -

Answer: C, D

QUESTION NO: 138Given:

What is the result when the programmer attempts to compile the code and run itwith 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 NO: 139Given:

What is the output?

Page 134: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 134 -

A. 42B. 420C. 462D. 42042E. Compilation failsF. An exception is thrown at runtime.

Answer: D

QUESTION NO: 140Assuming that the serializeBanana2() and the deserializeBanana2() methods willcorrectly use Java serialization and given:

What is the result?

A. Compilation failsB. 1 restored 42C. 12 restored 42D. 121 restored 42E. 1212 restored 42F. An exception is thrown at runtime

Page 135: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 135 -

Answer: D

QUESTION NO: 141Given:

What is the result?

A. a b cB. 1 2 3C. a1b2c3D. a1 b2 c3E. Compilation failsF. The code runs with no output.G. An exception is thrown at runtime.

Answer: AExplanation:codesample:import java.io.*;public class Q140{public static void main(String[] args) throws Exception{ Banana b=new Banana(); File objFile= new File("Q140.ser"); ObjectOutputStream objOS=new ObjectOutputStream(new FileOutputStream(objFile)); objOS.writeObject(b); ObjectInputStream objIS=new ObjectInputStream(new FileInputStream(objFile)); System.out.println("\n Deserialization \n"); Banana b2=(Banana)objIS.readObject();

}

}class Food {

Page 136: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 136 -

public Food(){ int a=1;System.out.print(" Food");}}class Fruit extends Food implements Serializable {public Fruit(){ int b=2;System.out.print(" Fruit");}}class Banana extends Fruit { int c=3;public Banana(){ System.out.print(" Banana");}

}

QUESTION NO: 142Given:

What is the result?

A. Compilation failsB. 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.

Answer: D

QUESTION NO: 143Given a valid DateFormat object named df, and

Page 137: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 137 -

What updates d's value with the date represented by ds?

A. AB. BC. CD. D

Answer: CExplanation:Code sample:

import java.io.*;public class Q214{public static void main(String[] args){ ReadFile rf=new ReadFile();}}class ReadFile{public ReadFile(){

Page 138: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 138 -

try{ File x1=new File("Q142.java"); FileReader x2=new FileReader(x1); BufferedReader x4=new BufferedReader(x2); String x3=null; while((x3=x4.readLine())!=null){

System.out.println(x3); } x4.close(); }catch(Exception err){ err.printStackTrace(); }}}

QUESTION NO: 144 DRAG DROPPlace the Fragments into the program, so that the program will get lines from a textfile, display them, and then close all the resources.

Page 139: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 139 -

Answer:Explanation: Pending. Send your suggestion to [email protected]

QUESTION NO: 145Given:

And:

Which changes can you make to Target without affecting Client?

A. Line 4 of class Target can be changed to retur i++;B. Line 2 of class Target can be changed to private int i = 1;C. Line 3 of class Target can be changed to private int addOne(){D. Line 2 of class Target can be changed to private Integer i = 0;

Answer: D

QUESTION NO: 146Given:

Page 140: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 140 -

Which statement is true?

A. Compilation will succeed if A extends B.B. Compilation will succeed if B extends A.C. Compilation will always fail because of an error in line7.D. Compilation will always fail because of an error in line8.

Answer: B

QUESTION NO: 147Given:

Page 141: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 141 -

And:

What is the result?

A. Compilation fails.B. Cannot add ToppingsC. The code runs with no output.D. A NullPointerException is thrown in Line 4.

Answer: A

QUESTION NO: 148 DRAG DROP

Page 142: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 142 -

Insert six modifiers into the code such that it meets all of these requirements:

Answer:Explanation:

Page 143: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 143 -

Firstly to meet the first condition the both classed should be declared as publicFor the second condition, the better approach is to define the alpha parameter as private;therefore outside classes would not have access to it.Regarding to the third condition the Alpha() method in Alpha class should be public. However, bydefining the Alpha(String a) as protected it says for those classes inside this class would haveaccess but the other classes out of this package won't have access.The order of answers isPublicPrivatePublicProtectedPublicPublic

Page 144: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 144 -

QUESTION NO: 149Given:

And:

What is the result?

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.

Answer: F

QUESTION NO: 150A programmer needs to create a logging method that can accept an arbitrarynumber of arguments. For example, it may be called in these ways:

Page 145: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 145 -

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 NO: 151Exhibit:

What is the result?

Page 146: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 146 -

A. 4321B. 0000C. An exception is thrown at runtime.D. Compilation fails because of an error in line 18.

Answer: DExplanation: Compilation fails because of an error in line 18) constructor Person()must be present in class Person for the compilation to succeed.

QUESTION NO: 152Given:

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

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 NO: 153Exhibit:

Page 147: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 147 -

Given this code from Class B:

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 in line 28.

Answer: A

QUESTION NO: 154Given:

Page 148: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 148 -

Which three methods, inserted individually at line 14, will correctly complete classTwo? ( 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: B, C, E

QUESTION NO: 155Given:

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

Page 149: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 149 -

Answer: A

QUESTION NO: 156Given:

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

Page 150: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 150 -

QUESTION NO: 157Given:

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() {/*do 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 NO: 158

Page 151: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 151 -

Which two code fragments correctly create and initialize a static array of intelements? (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: A, B

QUESTION NO: 159A UNIX user named Bob wants to replace his chess program with a new one, but heis not sure where the old one is installed. Bob is currently able to run a Java chessprogram starting from his home directory /home/bob using the command:Java -classpath /test:/home/bob/downloads/*.jar games.ChessBob's CLASSPATH is set (at login time) to:/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jarWhat is a possible location for the Chess.class file?

A. /test/Chess.classB. /home/bob/Chess.classC. /test/games/Chess.classD. /usr/lib/games/Chess.classE. /home/bob/games/Chess.classF. Inside jarfile /opt/java/lib/Games.jar (with a correct manifest)G. Inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)

Answer: C

QUESTION NO: 160Given:

Page 152: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 152 -

What is the result?

A. s 14B. s 16C. s 10D. Compilation failsE. An exception is thrown at runtime.

Answer: DExplanation:Option D is correct; in interface what ever is defined is considered as public, even if thereis no public keyword it considered as public not default.

QUESTION NO: 161Given:

Page 153: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 153 -

What is the result?

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].

Answer: D

QUESTION NO: 162Given:

And MainClass exists in the /apps/com/company/application directory. Assume theCLASSPATH environment variable is set to "." (current directory).Which two java commands entered at the command line will run MainClass?(Choose two.)

A. java MainClass if run from the /apps directoryB. java com.company.application.MainClass if run from the /apps directoryC. java -classpath /apps com.company.application.MainClass if run from any directoryD. java -classpath . Mainclass if run from the /apps/com/company/application directoryE. java -classpath /apps/com/company/application:. MainClass if run from the /apps

directoryF. java com.company.application.MainClass if run from the

/apps/com/company/application directory

Answer: B, C

Page 154: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 154 -

QUESTION NO: 163Given:

What is the result?

A. Compilation fails.B. An exception is thrown at runtime.C. The attribute id in the Item object remains unchanged.D. The attribute id in the Item object is modified to the new value.E. A new Item object is created with the preferred value in the id attribute.

Answer: AExplanation:It will cause compilation error because the id variable is final and the value of it can notbe changed.

QUESTION NO: 164A programmer has an algorithm that requires a java.util.List that provides anefficient implementation of add(0, object), but does NOT need to support quickrandom access.What supports these requirements?

A. java.util.QueueB. java.util.ArrayListC. java.util.LinearListD. java.util.LinkedList

Page 155: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 155 -

Answer: DExplanation:Efficient performance for Add(0,object) needs to have access to first element of the listand also less work for expanding the list such as avoiding shifting the elements.Additionally, the random access is not necessary therefore, data structures such as Arrayand LinearList would not be efficient. Queue will not be appropriate because to access thefirst elements all the elements should be poped from the queue and then pushed to queue!

QUESTION NO: 165Which two statements are true about the hashCode method? (Choose two.)

A. The hashCode method for a given class can be used to test for object equality andobject inequality for that class.

B. The hashCode method is used by the java.util.SortedSet collection class to order theelements within that set.

C. The hashCode method for a given class can be used to test for object inequality, butNOT object equality for that class.

D. The only important characteristic of the values returned by a hashCode method is thatthe distribution of valus must follow a Gaussian distribution.

E. The hashCode method is used by the java.util.HashSet collection class to group theelements within that set into hash buckets for swift retrieval.

Answer: C, EExplanation: The hashCode() mehod is first run against the given class if they bothhave the same hashCode then the equal method also checked, therefore, it is possiblethat the hashCode indicates the same but equal returns false.

QUESTION NO: 166 DRAG DROPGiven:

Page 156: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 156 -

Refractor this class to use generics without changing the code's behavior.

Code:import java.util.*;public class TestGenericConversion { public static void main(String []args){ //List list = new LinkedList();

List <String> list = new LinkedList<String>(); list.add("one");

Page 157: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 157 -

list.add("two");//System.out.println(((String)list.get(0)).length()); System.out.println((list.get(0)).length()); }}

Answer:Explanation:

QUESTION NO: 167 DRAG DROPGiven the class definitions:

Page 158: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 158 -

Place the correct Compilation Result on each takeList() method definition toindicate whether or not the go() method would compile given that definition.

Answer:Explanation:

Page 159: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 159 -

Public void takeList(ArrayList list){}Will compile successfully.Public void takeList(ArrayList<Animal> list){}Will fail because it requires Dog not Animal.Public void takeList(ArrayList<? Extends Animal> list){}Will compile successfully, cause Dog is compatible with Animal.Public void takeList(ArrayList<?> list){}Will compile successfully.Public void takeList(ArrayList list){}Will fail.

QUESTION NO: 168 DRAG DROPPlace the code in the appropriate place such that this program will always output [1,2].

Page 160: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 160 -

Answer:Explanation:

Page 161: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 161 -

The class should implements that Comparable to be sortable by sort method ofcollections.therefore, the compareTo method should be implemented.

Code sample:import java.util.*;public class Q168{public static void main(String[] args){ ArrayList<MyInt> list=new ArrayList<MyInt>(); list.add(new MyInt(2)); list.add(new MyInt(1)); Collections.sort(list); System.out.println(list);}}

Page 162: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 162 -

class MyInt implements Comparable{private int i;public MyInt(int i){this.i=i;}public String toString(){ return Integer.toString(i);}public int compareTo(Object o){ MyInt i2=(MyInt)o; return i-i2.i;}}

QUESTION NO: 169Given:

and:

A programmer iterates over the TreeSet and prints the name of each Drink object.What is the result?

A. TeaB. CoffeC. Coffe

Tea

Page 163: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 163 -

D. Compilation fails.E. The code runs with no outputF. An exception is thrown at runtime

Answer: BExplanation:The point is that the compareTo() method of Drink class always return 0, which means that theObject is equal to whatever it is compared to. Therefore, in a set which repetitive items are notallowed will just add the first added object which is one (Coffee) and when two (Tea) is added, itchecks it with one and it returns 0 which mean the elements already exists.

Source code:import java.util.*;

public class Drink implements Comparable { public String name; public int compareTo(Object o){ return 0; }

/** * @param strings */ public static void main(String...strings){ Drink one = new Drink(); Drink two = new Drink(); one.name="Coffee"; two.name="Tea"; TreeSet<Drink> set = new TreeSet<Drink>(); set.add(one); set.add(two); for(Drink d : set){ System.out.println(d.name); } }

}

QUESTION NO: 170

Page 164: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 164 -

Exhibit:

Which statement 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: DExplanation:D is correct, firstly the SomeException class should implements the Throwable interfaceor extends its implementation which is Exception, therefore it should beclass SomeException extends Exception{}

In class A, SomeException Class hasn't been used therefore its compilations will succeed,but in class B it throws a class which is not Throwable therefore compilation will fail.

QUESTION NO: 171Given:

Page 165: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 165 -

and:

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

A. StackOverflowErrorB. NullPointerExceptionC. NumberFormatExceptionD. IllegalArgumentExceptionE. ExceptionInInitializerError

Answer: A

QUESTION NO: 172Given:

What is the result?

A. 6

Page 166: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 166 -

B. 7C. 10D. 11E. Compilation failsF. An exception is thrown at runtime

Answer: EExplanation:The scope of declared variable in for statement is only in for block not outside of it.

QUESTION NO: 173Given:

What is the result?

A. threeB. otherC. 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 NO: 174 DRAG DROP

Page 167: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 167 -

Place the code elements into the class so that the code compiles and prints "Run.Run. Dolt." in exactly that order. Note that there may be more than one correctsolution.

Answer:Explanation:

Page 168: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 168 -

To control the process of thread execution rather than parallel execution. First we shouldwait for termination of first threat. After that the execution can be handled sequentially.

Code sample:public class Q174{public static void main(String[] args)throws InterruptedException{TesTwo t1= new TesTwo();t1.start();t1.join();t1.run();t1.doIt();}}class TesTwo extends Thread{public void run(){ System.out.print("Run. ");}public void doIt(){System.out.print("Do it. ");}}

QUESTION NO: 175Given:

Page 169: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 169 -

Which two changes, taken together, would generate the output 1, 2, 3, 4, 5, ?(Choose two.)

A. move the line 12 print statement into the foo() methodB. 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 ) blockE. wrap the loop code inside the go() method with a synchronized block synchronized(

this ) { // for loop code here }

Answer: A, D

QUESTION NO: 176 DRAG DROPPlace the code elements in position so that the Flags2 class will compile and makeappropriate use of the wait/notify mechanism.Note: You may reuse code elements.

Page 170: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 170 -

Answer:Explanation:

Page 171: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 171 -

Code sample:public class Q176{}class Flag{private boolean isReady=false;public synchronized void produce(){ isReady=true; notifyAll();}public synchronized void consume(){ while(!isReady){ try{ wait(); }catch(Exception err){ } isReady=false; }}}

QUESTION NO: 177 DRAG DROPGiven:

Page 172: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 172 -

Assume that sleep(n) executes in exactly n milliseconds, and all other code execute inan insignificant amount of time.Place the fragments in the output area to show the result of running this code.

Answer:Explanation:

QUESTION NO: 178Given:

Page 173: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 173 -

What is the result?

A. Compilation fails.B. An exception is throw at runtimeC. The code executes normally and prints "bar".D. The code executes normally, but nothing prints.

Answer: C

QUESTION NO: 179Given:foo and bar are public references available to many other threads. foo refers to aThread and bar is an Object. The thread foo is currently executing bar.wait().

From another thread, what provides the most reliable way to ensure that foo willstop executing wait()?

A. foo.notify();B. bar.notify();C. foo.notifyAll();D. Thread.notify();E. bar.notifyAll();F. Object.notify();

Answer: E

Page 174: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 174 -

QUESTION NO: 180Given:

What is the result?

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

Answer: B

QUESTION NO: 181Which two statements are true? (Choose two)

A.An encapsulated,public class promoters re-use.B.Classes that share the same interface are always tightly encapsulatedC.An encapsulated class allows subclasses to overload methods,but does NOT allowoverriding methodsD.An encapsulated class allows a programmer to change an implementation withoutaffecting outside code

Answer: A, D.

Page 175: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 175 -

QUESTION NO: 182hat is the output if the main() method is run?

Given:

10. public class Starter extends Thread { 11. private int x = 2; 12. public static void main(String[] args) throws Exception { 13. new Starter().makeItSo(); 14. } 15. public starter() { 16. x = 5; 17. start(); 18. } 19. public void makeItSo() throws Exception { 20. join(); 21. x = x - 1; 22. System.out.printIn(x); 23. } 24. public void run() { x *= 2;} 25. }

A.4B.5C.8D.9E.Compilations fails.F.An exception is thrown at runtimeG.It is impossible to determine for certain

Answer: D

QUESTION NO: 183 DRAG DROPPlace the code fragments into position to produice the output:

true true false

Page 176: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 176 -

Answer:Explanation:

Page 177: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 177 -

Here ,the while condition is verified by using,while(scanner.next()) ---> this willnot return boolean.it should be used to move thetext pattern for the next search.

This needs to be tested ,like this,while(scanner.HasNext()) --> return true or false.Next,if(scanner.nextBoolean())--> this will work only, if the next value boolean value istrue.Here, we test the type of the text only,not the value of the text.This needs to be updated like,if(scanner.hasNextBoolean())--> this checks the type of the text is boolean or not.Then should print,System.out.println(scanner.nextBoolean())--> This will print the value of theboolean text.In the else part, we should move to the next text in the pattern.For this, weshould use. Then only the search engine will move to the next text.

else{scanner.next();

Page 178: TestKing Java 310-055 v12 SCJP Java 2 Platform Std. Ed. 5.0

Leading the way in IT testing and certification tools, www.testking.com

- 178 -

}