Exam : 310-055
Title : Sun Certified Programmer for the Java 2
Platform, Standard Edition 5.0
Ver : 07.09.07
310-055
QUESTION 1
Given the code in the exhibit.
What is the result?
A. Compilation fails
B. An exception is thrown at runtime.
C. An instance of Forest is serialized.
D. An instance of Forest and an instance of Tree are both serialized.
Answer: B
QUESTION 2
Which code, inserted ay line 14, will allow this class to correctly serialized and
desterilize?
310-055
A. S. default ReadObject ( );
B. This = s.defaultReadObject ( );
C. Y = s. default ( ) ; x = s.readInt ( );
D. X = s. readInt; y = s. readInt ( );
Answer: D
QUESTION 3
Given the exhibit.
What is the result?
A. 0
B. 1
C. 4
D. Compilation fails
E. An exception is thrown at runtime
Answer: D
QUESTION 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-2004
B. The value of S is Dec 14, 2000
C. An exception is thrown at runtime
D. Compilation fails because of an error in line 13.
Answer: D
QUESTION 5
DRAG DROP
The doesFileExist method takes an array of directory names representing a path
from 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.
310-055
Answer:
Explanation:
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,String
filename){
String path = "";
for(String dir: directories){
path = path +File.separator+dir;
//path = path.getSubdirectory(dir);
}
System.out.println(path);
310-055
File file = new File(path,filename);
return file.exists();
}}
QUESTION 6
DRAG DROP
Given:
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:
QUESTION 7
When comparing java. Io. BufferedWriter to java.io.FileWriter, which capability
exist as a method in only one of the two?
A. closing the stream
B. flushing the stream
C. writing to the stream
D. marking a location in the stream
E. writing a line separator to the stream
Answer: E
QUESTION 8
Given the exhibit:
310-055
Which two code fragments, inserted independently at line 3, generate the output
4247? (choose two)
A. String s = "123456789"
S. = (s-"123").replace (1,3, "24") - "89";
B. StringBuffer s = new StringBuffer ("123456789");
S.delete (0,3) replace(1,3,"24"). Delete (4,6)
C. StringBuffer s = new StringBuffer ("123456789");
S.substring (3,6).delete(1,3). insert (1, "24").
D. StringBuilder s = new StringBuilder ("123456789");
S.substring (3,6) delete (1,2). insert (1, "24")
E. StringBuilder s = new StringBuilder ("123456789");
S.delete (0,3) replace(1,3,). Delete (2,5) insert (1, "24")
Answer: B,E
QUESTION 9
Which three statements concerning the use of the java . io. Realizable interface are
true? (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 and
deserialization
D. The values in field with the transient modifier will NOT survive serialization and
deserialization
E. It is legal to serialize an object of a type that has a supertype that does NOT implement
java .io.Serialization
Answer: B,D,E
QUESTION 10
Given the exhibit:
310-055
What is the result?
A. short Long
B. SHORT LONG
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
QUESTION 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's
date?
A. Local loc = Local.getLocal ( );
System.out printIn (loc.getDisplayCountry ( )
B. Local loc = Local.getDefault ( );
System.out printIn (loc.getDisplayCountry ( )
+ " " " +df. Format (d) );
C. Local loc = Local.getLocal ( );
System.out printIn (loc.getDisplayCountry ( )
+ " " +df. setDateFormat (d) ) ;
D. Local loc = Local.getDefault ( );
System.out printIn (loc.getDisplayCountry ( )
+ " " +df.seDateFormat (d) );
Answer: B
QUESTION 12
Given the exhibit:
310-055
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime
C. The code executes and prints " running"
D. The code executes and prints "runningrunning"
E. The code executes and prints "runningrunninigrunning
Answer: E
QUESTION 13
Exhibit:
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,
310-055
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,C
QUESTION 14
Given the exhibit:
Which statement is rue?
A. This code may throw an InterruptedException
B. This code may throw an IllegalStateExcepion
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. Reversing the order of obj.wait ( ) and obj. notify ( ) may vcause this method to
complete normally
Answer: B
QUESTION 15
Given the exhibit:
What can be a result?
310-055
A. Compilation fails
B. An exception is thrown at runtime
C. The code executes and prints "StartedComplete"
D. The code executes and prints "StartedComplete0123"
E. The code executes and prints "Started0123Complete"
Answer: E
QUESTION 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 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 ( ) {
310-055
synchronized (o) { /* code here */ }
}
Answer: C,E,F
QUESTION 18
Exhibit:
What is the result?
A. The code will deadlock
B. The code may run with no output
C. An exception is thrown at runtime
D. The code may run with output " 0 6 "
E. The code may run with output "2 0 6 4"
310-055
F. The code may run with output "0 2 4 6"
Answer: F
QUESTION 19
Given the exhibit:
What is the result?
A. Compilation fails
B. An exception is thrown at runtime
C. The code executes normally and prints "sleep"
D. The code executes normally, but nothing is printed.
Answer: C
QUESTION 20
Which two statements are true about has-a and is a relationships? (choose two)
A. Inheritance represents an is -a relationship
B. Inheritance represents a has-a relationship
C. Interfaces must be used when creating a has-a relationship
D. Instance variables can be used when creating a has-a relationship
Answer: A,D
QUESTION 21
Given the exhibit:
What can directly access and change the value of the variable name?
A. any class
B. only the Target class
C. any class in the Certkiller package
D. any class that extends Target
Answer: C
310-055
QUESTION 22
Which three statements are true? (choose three)
A. A final method in class x can be abstract if and only if X is abstract
B. 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 explicitly
referencing the class x.
F. A method with the same signature as a private final method in class X can be
implemented in a subclass of X.
Answer: B,E,F
QUESTION 23
DRAG DROP
Place the Types in one of the Type columns, and the Relationships in the
Relationship column, to define appropriate has-a and is-a relationships.
Answer:
310-055
QUESTION 24
DRAG DROP
Replace two of the Modifiers that appear in the Single class to make the code
compile.
Note: Three modifiers will not be used and four modifiers in the code will remain
unchanged.
Answer:
QUESTION 25
Exhibit:
310-055
What is the result?
A. Value is : 8
B. Compilation fails.
C. Value is : 12
D. Value is ; -12
E. The code runs with no output
F. An exception is thrown at runtime.
Answer: A
QUESTION 26
Given the exhibit:
310-055
Which statement is true?
A. The class is fully encapsulated
B. The code demonstrates polymorphism.
C. The ownerName variable breaks encapsulation
D. The CardID and limit variables break polymorphism
E. The setCardInformation method breaks encapsulation
Answer: C
QUESTION 27
Given the exhibit:
What is the result?
A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime
Answer: E
310-055
QUESTION 28
Exhibit:
What two must the programmer do to oerrect the compilation errors?
A. insert a call to this ( ) in the Car CONSTRUCTOR
B. insert a call to this ( ) in the MeGo constructor
C. insert a call to super ( ) in the MeGo constructor
D. insert a call to super (vin) in the MeGo constructor
E. change the wheel Count variable in CAR TO PROTECTED
F. CHANGE LINE 3 IN THE MeGo class to super wheel Count =3;
Answer: D,E
QUESTION 29
Given the exhibit:
What three code fragments inserted individually at line 15, make use of
polymorphism? (choose three)
310-055
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 30
Given the exhibit:
Which statement should be placed at line 14 to suggest that the virtual machine
expend effort toward recycling the memory used by the object Certkiller ?
A. System.gc ( )
B. Runtime. Gc ( )
C. System.freeMemory ( )
D. Runtime.getRuntime ( ) growHeap ( )
E. Runtime.getRuntime ( ) free Memory ( )
Answer: A
QUESTION 31
Exhibit:
310-055
What is the output of the program shown in the exhibit?
A. 300.100.100.100.100
B. 300.300.100.100.100
C. 300.300.300.100.100
D. 300.300.300.300.100
Answer: B
QUESTION 32
A developer is creating a class Book, that needs to acces class Paper. The Paper
class is deployed in a JAR named myLib.jar.
Which three, taken independently, will allow the developer to use the Paper class
while compiling the Book class? (choose three)
A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar
B. 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 set
that includes /foo/myLib.jar/Paper,Class.
D. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set
that includes /foo/myLib.jar.
E. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac
310-055
-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 33
Given the exhibit:
Which statement is true about the object referenced by snoog, smooch and booch
immediately after line 23 executes?
A. None of these objects are eligible for garbage collection
B. Only the object referenced by booch is eligible for garbage collection
C. Only the pbject referenced by snoog is eligible for garbage colletion
D. Only the object referenced by smooch is eligible for garbage collection
E. The objects referenced by smooch and booch are eligible for garbage collection
Answer: E
QUESTION 34
Given the exhibit:
310-055
and the command line invocation
java Certkiller 5 a b c
what is the result?
A. a b
B. b c
C. a b c
d. Compilation fails
C. An exception is thrown at runtime
Answer: B
QUESTION 35
Given the exhibit:
What is the result?
A. r, t, t
B. r, e, o,
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
QUESTION 36
Given the exhibit:
310-055
and the command line:
java - Drop.custom = gobstopper Certkiller
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,E
QUESTION 37
Given classes defined in two different files:
What is required at line 5 in class Certkiller App to use the process method of Bit Utils?
A. Process (bytes);
B. BitUtils.process (bytes);
C. Util.BitUtils.process (bytes);
D. Certkiller App cannot use methods in BitUtils
E. Import util.BitUtils.*; process (bytes);
Answer: C
QUESTION 38
Exhibit:
310-055
What is the outcome of the code?
A. Compilation fails.
B. Gobstopper
Fizzylifting
C. Gobstopper
Scremdiddlyumptious
D. Scrumdiddlyumptious
Fizzylifting
E. Scrumiddlyumptious
Scrumdiddlyumptious
Answer: B
QUESTION 39
Given classes defined in two different files
310-055
What is required at line 5 in class Certkiller Application to use the process method of
BitUtils?
A. PROCESS (BYTES);
B. BitUtils.process(bytes);
C. App.BitUtils.process (bytes)
D. Util.BitUtils. process (bytes)
E. Import util.BitUtils.*; process (bytes);
F. Certkiller Application cannot use the process method in BitUtils.
Answer: F
QUESTION 40
DRAG DROP
The image represents a complete package structure for a set of classes: "com" is the
beginning of the fully-qualified package name for all classes.
Give this package structure, insert the code needed to make the Car class compile
and runt successfully.
All three placeholds must be filled. If fewer than three statement are needed, use the
"// blank" options.
310-055
Answer:
QUESTION 41
Given the exhibit:
310-055
What is the result when this ode executed?
A. 1
B. 3
C. 123
D. 321
E. The code runs with no output
Answer: C
QUESTION 42
DRAG DROP
Place the code fragments in position to complete the Displayable interface.
Answer:
QUESTION 43
Given the exhibit:
310-055
Which code, inserted at line 14, allows the Sprite class to compile?
A. Direction d = NORTH
B. Certkiller .Direction d = NORTH
C. Direction d = Direction.NORTH
D. Certkiller .Direction d = Certkiller Direction. NORTH
Answer: D
QUESTION 44
Exhibit:
Which three statements are true? (Choose three)
A. Compilation fails
B. The code compiles and the output is 2
C. If lines 16, 17 and 18 were removed, compilation would fail.
D. If lines 24,25, and 26 were removed, compilation would fail.
E. If lines 16,17 and 18 were removed, the code would compile and the output would be
310-055
2.
F. If line 24,25 and 26 were removed, the code would compile and the output would be 1.
Answer: B,E,F
QUESTION 45
DRAG DROP
Add methods to the Beta class to make it compile correctly.
Answer:
QUESTION 46
Given the exhibit:
What is the output from line 5 of the Certkiller class?
310-055
A. 5
B. 10
C. 12
D. 17
E. 24
Answer: B
QUESTION 47
Given the exhibit:
Which two methods, inserted individually, correctly complete the Certkiller 3 class?
(choose two)
A. public void fooo ( ) { }
B. public int foo ( ) {return 3: }
C. public Certkiller 2 foo ( ) {return this;}
D. public Certkiller 1 foo ( ) {return this}
Answer: C,D
QUESTION 48
Exhibit:
310-055
What is the result?
A. snootchy 420 third second first
B. snootchy 420 first second third
C. first second third snootchy 420
D. third second first snootchy 420
E. thirds first second snootchy 420
F. first second first third snootchy 420
Answer: D
QUESTION 49
Given the exhibit:
What is the result?
A. 1 2 3
B. Compiltion fails because of an error in line 12.
C. Compilation fails because of an error in line 13
310-055
D. Compilation fails because of an error in line 14.
E. A ClassCastException is thrown at runtime
Answer: A
QUESTION 50
A Java Bean component has the following field:
11. PRIVATE BOOLEAN ENABLED:
Which two pairs of method declarations follow the JavaBean standard for accessing
this 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 ( )
Answer: A,C
QUESTION 51
Given the exhibit:
Which two statements are true? (choose two)
A. Certkiller .beta ( ) is a valid invocation of beta ( )
B. Certkiller .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 52
Given the exhibit:
310-055
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
QUESTION 53
Given the exhibit:
310-055
What is the result
A. B
B. The code exception is thrown at runtime
C. 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 54
Given the exhibit:
What is the result if NullPointerException occurs on line 34?
A. c
B. a
C. ab
D. ac
E. bc
F. abc
Answer: D
QUESTION 55
Given the exhibit:
310-055
Which exception or error will be thrown when a programmer attempts to run this
code?
A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitoatializerError
D. java.lang.ArrayIndexOutOfBoundsException
Answer: C
QUESTION 56
Exhibit:
Which two statements are truee if a NullPointerException is thrown on line 3 of
class C? (choose two)
310-055
A. The application will crash.
B. The code on line 29 will be executed
C. The code on line 5 of class A will execute.
D. The code on line 5 of class B will execute.
E. The exception will be propagated back to line 27.
Answer: B,E
QUESTION 57
Given the exhibit:
What is the result?
A. 0
B. 10
C. 12
D. Line 29 will never be reached.
Answer: C
QUESTION 58
Given the exhibit:
What is the result?
A. The value "4" is printed at the command line
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPOINTEReXCEPTION OCCURS AT RUNTIME.
E. A NumberFormatException occurs at runtime.
310-055
F. An IllegalStateException occurs at runtime.
Answer: D
QUESTION 59
Given the exhibit:
What is the result?
A. 3, 2, 1,
B. 1, 2, 3,
C. Compilation fails
D. The code runs with no output
E. An exception is thrown at runtime
Answer: C
QUESTION 60
Given the exhibit:
What is the result when method testIfA is invoked?
A. True
B. Not true
C. An exception is thrown at runtime
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
310-055
Answer: A
QUESTION 61
GIVEN THE EXHIBIT:
Which statement is true?
A. All of the assert statements are used appropriately.
B. Only the assert statement on line 31 is used appropriately
C. The assert statements on lines 29 and 31 are used appropriately
D. The assert statements on lines 26 and 29 are used appropriately
E. The assert statements on lines 29 and 33 are used appropriately
F. The assert statements on lines 29 ,31and 33 are used appropriately
G. The assert statements on lines 26,29 and 31 are used appropriately
Answer: C
310-055
QUESTION 62
GIVEN THE EXHIBIT:
What is the result?
A. null
B. zero
C. some
D. Compilation fails
E. An exception is thrown at runtime
Answer: D
QUESTION 63
Given the exhibit:
What is the result?
A. test
B. Exception
C. Compilation fails
D. NullPointerException
Answer: C
QUESTION 64
Given the exhibit:
310-055
What is the result?
A. Compilation fails
B. aAaA aAa AAaa AaA
C. AAaa AaA aAa aAaA
D. AaA AAaa aAaA aAa
E. aAa AaA aAaA AAaa
F. An exception is thrown at runtime
Answer: C
QUESTION 65
Given the exhibit:
What is the result?
A. 0
B. 1
C. 2
D. 3
E. 4
310-055
F. Compilation fails.
G. An exception is thrown at runtime
Answer: D
QUESTION 66
Given a pre-generics implementation of a method:
Which three changes must be made to the method sum to use generics? (choose
three)
A. remove line 14
B. 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 67
Given the exhibit:
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.
310-055
D. A ClassCastExceptation occurs in line 31.
E. The value of all four object prints in natural order.
Answer: C
QUESTION 68
DRAG DROP
Place the code into position to create a class that maps from Strings to integer
values.
The result of execution must be [one]. Some options may be used more than once.
Answer:
310-055
Explanation:
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 69
DRAG DROP
Place a result onto each motho call to indicate what would happen if the method call
were inserted at line 9. Note: Results can be used more than once.
310-055
Answer:
QUESTION 70
Given the exhibit:
What is the result?
A. apple:apple
B. carrot:apple
C. apple:banana
D. banana:apple
E. carrot:carrot
F. carrot:banana
Answer: C
310-055
QUESTION 71
Given :
A programmer is developing a class Key, that will be used as a key in a standard
java.util.HashMap.
Which two methods should be overridden to assure that key works correctly as a
key? (choose two)
A. public int hashCode ( )
B. public Boolean equals (Key k)
C. public int compareTo (object o
D. public Boolean equals (object o)
Answer: A,D
QUESTION 72
Given the exhibit:
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 73
Given the exhibit:
310-055
enumExample { ONE, TWO, THREE }
Which statement is true?
A. The expressions (ONE = = ONE) and ONE.equals (ONE) are both guaranteed to be
true.
B. The expression (ONE < TWO ) is guaranteed to be true and ONE.compareTo (TWO)
is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HasMap.; instead, the
programmer must use a java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT be
sorted because enumerated Type do NOT IMPLEMENT JAVA.LANG.Comparable.
Answer: A
QUESTION 74
Given:
Which line of code marks the earliest point that an object referenced by intObj
becomes a candidate for garbage collection?
A. Line 16
B. Line 17
C. Line 18
D. Line 19
E. The object is NOT a candidate for garbage collection.
Answer: D
QUESTION 75
Given:
andthe command line invocation:
javaYippee2 a b c
What is the result?
310-055
A. a b
B. b c
C. a b c
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: B
QUESTION 76
A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants
to execute the main method of Poker on a UNIX system using the command:
Java games.cards.Poker
What allows the user to do this?
A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java
B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include
/stuff/java/*.jar
C. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include
/stuff/java/Poker.jar
D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include
/stuff/java
E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include
/stuff/java/*.jar
F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include
/stuff/java/Poker.jar
Answer: C
QUESTION 77
Exhibit:
310-055
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 );
Answer: B, C, F
QUESTION 78
Given a class Repetition:
And given another class Demo:
310-055
Which code should be inserted at line 1 of Demo.java to compile and run Demo to
print "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
QUESTION 79
Given:
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 80
Exhibit:
310-055
Given the fully-qualified class names:
com.foo.bar.Dog
com.foo.bar.blatz.Book
com.bar.Car
com.bar.blatz.Sun
Which graph represents the correct directory structure for a JAR file from which
those classes can be used by the compiler and JVM?
A. Jar A
B. Jar B
C. Jar C
D. Jar D
E. Jar E
Answer: A
QUESTION 81
Given:
and two separate command line invocations:
310-055
java Yippee
java 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
QUESTION 82
Given:
What is the result?
A. Compilation fails
B. An exception is thrown at runtime
C. doStuff x = 6 main x = 6
D. doStuff x = 5 main x = 5
E. doStuff x = 5 main x = 6
F. doStuff x = 6 main x = 5
Answer: D
QUESTION 83
Given:
310-055
When the doSomething method is called, after which line does the Object created in
line 5 bbecome available for garbage collection?
A. Line 5
B. Line 6
C. Line 7
D. Line 8
E. Line 9
F. Line 10
Answer: D
QUESTION 84
Given:
What is the result?
A. Exception
B. A, B, Exception
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 14.
E. A NullPointerException is thrown at runtime.
Answer: D
QUESTION 85
Given:
310-055
What is the result?
A. harrier
B. shepherd
C. retriever
D. Compilation fails
E. retriever harrier
F. An exception is thrown at runtime.
Answer: D
QUESTION 86
Given:
What is the result?
A. A, B, C
B. B, C, A
C. Compilation fails
D. The code runs with no output
E. An exception is thrown at runtime
Answer: B
QUESTION 87
Given:
310-055
What is the result?
A. end
B. Compilation fails
C. exception end
D. exception test end
E. A Throwable is thrown by main
F. An Exception is thrown by main
Answer: E
QUESTION 88
Given:
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: B, C, E
QUESTION 89
Given:
310-055
What is the result?
A. Compilation fails
B. pi is bigger than 3.
C. An exception occurs at runtime.
D. pi is bigger than 3. Have a nice day.
E. pi is not bigger than 3. Have a nice day.
Answer: A
QUESTION 90
Given:
Which code, inserted at line 16 will cause a java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f = (Delta)x;
C. Foo f = (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Answer: B
QUESTION 91
Given a method that must ensure that its parameter is not null:
310-055
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 92
DRAG DROP
Place the correct Code in the Code Sample to achieve the expected results.
Expected results:
Output: 1 2 4 8 16 32
Code Sample
Answer:
QUESTION 93
Given:
310-055
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2
F. java -ea:test test file1
Answer: B, E
QUESTION 94
Given:
Which statement is true if a ResourceException is thrown on line 86?
A. Line 92 will not execute.
B. The connection will not be retrieved in line 85.
C. The resource connection will not be closed on line 88.
D. The enclosing method will throw an exception to its caller.
Answer: C
QUESTION 95
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly
use Java serialization and given:
310-055
What is the result?
A. restore 400
B. restore 403
C. restore 453
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: C
QUESTION 96
Given:
What is the result?
A. Compilation fails
B. Pi is approximately 3.
C. Pi is approximately 3.141593.
D. An exception is thrown at runtime.
Answer: D
QUESTION 97
Given:
What is the result?
310-055
A. int Long
B. Short Long
C. Compilation fails
D. An exception is thrown at runtime.
Answer: A
QUESTION 98
DRAG DROP
Chain these constructors to create objects to read from a file named "in" and to
write to a file named "out".
Answer:
Explanation:
Sample code:
import java.io.*;
public class Files {
public static void main(String []args){
try{
BufferedReader reader = new BufferedReader(new
FileReader("in"));
PrintWriter writer = new PrintWriter(new BufferedWriter(new
FileWriter("out")));
} catch (Exception ex){
System.out.println("Exception!!");
} }
}
QUESTION 99
DRAG DROP
Place the code fragments into position to use a BufferedReader to read in an entire
text file.
310-055
Answer:
QUESTION 100
Given this method in a class:
Which statement is true?
A. This code is NOT thread-safe.
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform poorly. For better performance, the code should be rewritten:
return "<" + this.name + ">";
310-055
D. This code will perform well and converting the code to use StringBuilder will not
enhance the performance.
Answer: B
QUESTION 101
Given:
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
QUESTION 102
Given:
Which two statements are true about the result if the locale is Locale.US? (Choose
two.)
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.
310-055
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 103
DRAG DROP
Place the correct description of the compiler output on the code fragment to be
inserted at line 4 and 5. The same compiler output may be used more than once.
Answer:
QUESTION 104
Given:
Which three will compile successfully? (Choose three.)
310-055
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 105
Exhibit:
Which statement is true about the set variable on line 12?
A. The set variable contains all six elements from the coll collection, and the order is
guaranteed to be preserved.
B. The set variable contains only three elements from the coll collection, and the order is
guaranteed to be preserved.
C. The set variable contains all six elements from the coll collection, but the order is
NOT guaranteed to be preserved.
D. The set variable contains only three elements from the coll collection, but the order is
NOT guaranteed to be preserved.
Answer: D
QUESTION 106
Given:
310-055
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: B
QUESTION 107
Given:
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: A
QUESTION 108
Given:
310-055
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 109
Given:
What, inserted at line 39, will sort the keys in the props HashMap?
A. Array.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s = new SortedSet(s);
Answer: B
QUESTION 110
DRAG DROP
Place code into the class so that it compiles and generates the output answer=42.
Note: Code options may be used more than once.
310-055
Answer:
QUESTION 111
DRAG DROP
Given:
Place the Compilation Results on each code statement to indicate whether or not
that code will compile if inserted into the takeList() method.
Answer:
QUESTION 112
Which two code fragments will execute the method doStuff() in a separate thread?
(Choose two.)
A. new Thread() {
public void run() { doStuff() ;}
310-055
};
B. new Thread() {
public void start() { doStuff(); }
};
C. new Thread() {
public void start() { doStuff(); }
}.run();
D. new Thread() {
public void run() { doStuff(); }
}.start();
E. new Thread(new runnable() {
public void run() { doStuff(); }
}).run();
F. new Thread(new runnable() {
public void run() { doStuff(); }
}).start();
Answer: D, F
QUESTION 113
Given:
Which to can be results? (Choose two.)
A. java.lang.RuntimeException: Problem
B. run.
java.lang.RuntimeException: Problem
C. End of method.
java.lang.RuntimeException: Problem
D. End of method.
run.
java.lang.RuntimeException: Problem
E. run.
java.lang.RuntimeException: Problem
End of method
Answer: D, E
310-055
QUESTION 114
Given:
Which three changes should be made to adapt this class to be used safely by
multiple threads? (Choose three.)
A. declare reset() using the synchronized keyword
B. declare getName() using the synchronized keyword
C. declare getCount() using the synchronized keyword
D. declare the constructor using the synchronized keyword
E. declare increment() using the synchronized keyword
Answer: A, C, E
QUESTION 115
Given:
Which statement is true?
A. Compilation fails
B. 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.
Answer: E
310-055
QUESTION 116
Given:
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: B
QUESTION 117
Given:
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 118
DRAG DROP
Place the Output Options in the Actual Output Sequence to indicate the output
from this code:
310-055
Answer:
QUESTION 119
Given:
What is the result?
A. 0 . 0
B. Compilation fails.
C. A ParseException is thrown by the parse method at runtime.
D. A NumberFormatException is thrown by the parse method at runtime.
Answer: B
310-055
QUESTION 120
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 121
Given:
Which code, inserted at line 15, creates an instance of the Point class defined in
Line?
A. Point p = new Point();
B. Line.Point p = new Line.Point();
C. The Point class cannot be instatiated at line 15.
D. Line l = new Line() ; l.Point p = new l.Point();
Answer: B
310-055
QUESTION 122
Given:
Which statement is true?
A. The code will compile without changes.
B. The code will compile if public Tree() { Plant(); } is added to the Tree class.
C. The code will compile if public Plant() { Tree(); } is added to the Plant class.
D. The code will compile if public Plant() { this("fern"); } is added to the Plant class.
E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class.
Answer: D
310-055
QUESTION 123
Given:
Which two code fragments, inserted independently at line 12, will allow the class to
compile? (Choose two.)
A. foreach( x ) System.out.println(z);
B. for( int z : x ) System.out.println(z);
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 124
Exhibit:
Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
D. Compilation of class AImpl will fail because of an error in line 2.
Answer: C
QUESTION 125
DRAG DROP
Place the lines in the correct order to complete the enum.
enumElement {
310-055
Answer:
Explanation:
Code:
enum enumElement {
EARTH,WIND,FIRE {
public String info(){
return "Hot";
}
}
};
public String info(){
return "element";
}
QUESTION 126
DRAG DROP
Place the code elements in order so that the resulting Java source file will compile
correctly, resulting in a class called com.sun.cert.AddressBook.
310-055
Answer:
QUESTION 127
Which two classes correctly implement both the java.lang.Runnable and the
java.lang.Clonable interfaces? (Choose two.)
A. public class Session
implements Runnable, Clonable {
public void run();
public Object clone();
}
B. public class Session
extends Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
}
C. public class Session
implements Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
310-055
}
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 128
Given:
Which statement is true?
A. 420 is the output
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier.
E. Constructors CANNOT use the protected modifier.
Answer: A
QUESTION 129
Given:
What is the result?
A. foofoofoofoofoo
310-055
B. foobarfoobarbar
C. foobarfoofoofoo
D. foobarfoobarfoo
E. barbarbarbarbar
F. foofoofoobarbar
G. foofoofoobarfoo
Answer: D
QUESTION 130
Which 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 131
Given:
Which statement is true about the class of an object that can reference the variable
base?
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.
Answer: C
QUESTION 132
DRAG DROP
Given:
310-055
Place the names "A" and "B" in the following output.
Answer:
QUESTION 133
Given:
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()
310-055
defined in line 9.
Answer: F
QUESTION 134
Which 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 135
DRAG DROP
Place the Relations on their corresponding Implementation Structures.
Note: Not all Implementation Structres will be used.
Answer:
QUESTION 136
Given:
310-055
And:
What is the result?
A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime.
Answer: C
QUESTION 137
Given:
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);}
310-055
Answer: C, D
QUESTION 138
Given:
What is the result when the programmer attempts to compile the code and run it
with the command java Converter 12?
A. It is true that j= =i.
B. It is false that J= =i.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 13.
Answer: D
QUESTION 139
Given:
What is the output?
A. 42
B. 420
C. 462
D. 42042
E. Compilation fails
F. An exception is thrown at runtime.
Answer: D
QUESTION 140
Assuming that the serializeBanana2() and the deserializeBanana2() methods will
correctly use Java serialization and given:
310-055
What is the result?
A. Compilation fails
B. 1 restored 42
C. 12 restored 42
D. 121 restored 42
E. 1212 restored 42
F. An exception is thrown at runtime
Answer: D
QUESTION 141
Given:
What is the result?
A. a b c
B. 1 2 3
C. a1b2c3
D. a1 b2 c3
E. Compilation fails
F. The code runs with no output.
G. An exception is thrown at runtime.
Answer: A
QUESTION 142
Given:
What is the result?
310-055
A. Compilation fails
B. After line 15, the value of age is 5.
C. After line 15, the value of age is 3.
D. An exception is thrown at runtime.
Answer: D
QUESTION 143
Given a valid DateFormat object named df, and
What updates d's value with the date represented by ds?
A. A
B. B
C. C
D. D
Answer: C
QUESTION 144
DRAG DROP
Place the Fragments into the program, so that the program will get lines from a text
file, display them, and then close all the resources.
310-055
Answer:
QUESTION 145
Given:
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 146
Given:
310-055
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 147
Given:
And:
What is the result?
A. Compilation fails.
B. Cannot add Toppings
C. The code runs with no output.
D. A NullPointerException is thrown in Line 4.
Answer: A
310-055
QUESTION 148
DRAG DROP
Insert six modifiers into the code such that it meets all of these requirements:
Answer:
QUESTION 149
Given:
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 150
A programmer needs to create a logging method that can accept an arbitrary
number of arguments. For example, it may be called in these ways:
310-055
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 151
Exhibit:
What is the result?
A. 4321
B. 0000
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 18.
Answer: D
Explanation: Compilation fails because of an error in line 18) constructor Person()
must be present in class Person for the compilation to succeed.
QUESTION 152
Given:
310-055
Which code inserted at line 14 causes the foo method to print RED, GREEN, and
BLUE?
A. for( Color c : Color.values() )
B. for( Color c = RED; c<= BLUE; c++ )
C. for( Color c ; c.hasNext() ; c.next() )
D. for( Color c = Color[0]; c <= Color[2]; c++)
E. for( Color c = Color.RED; c <= Color.BLUE; c++)
Answer: A
QUESTION 153
Exhibit:
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 154
Given:
Which three methods, inserted individually at line 14, will correctly complete class
Two? ( Choose three.)
310-055
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 155
Given:
A programmer wants to create an interface called B that has A as its parent.
Which interface declaration is correct?
A. public interface B extends A {}
B. public interface B implements A {}
C. public interface B instanceOf A {}
D. public interface B inheritsFrom A {}
Answer: A
QUESTION 156
Given:
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();
310-055
D. Shape s = new Circle();
s->setAnchor(10,10);
s->draw();
E. Circle c = new Circle();
c.Shape.setAnchor(10,10);
c.shape.draw();
Answer: C
QUESTION 157
Given:
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 158
Which two code fragments correctly create and initialize a static array of int
elements? (Choose two.)
A. static final int[] a = { 100,200 };
B. static final int [] a;
310-055
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 159
A UNIX user named Bob wants to replace his chess program with a new one, but he
is not sure where the old one is installed. Bob is currently able to run a Java chess
program starting from his home directory /home/bob using the command:
Java -classpath /test:/home/bob/downloads/*.jar games.Chess
Bob's CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar
What is a possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. 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 160
Given:
What is the result?
A. s 14
B. s 16
C. s 10
D. Compilation fails
E. An exception is thrown at runtime.
Answer: B
310-055
QUESTION 161
Given:
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 162
Given:
And MainClass exists in the /apps/com/company/application directory. Assume the
CLASSPATH 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 directory
B. java com.company.application.MainClass if run from the /apps directory
C. java -classpath /apps com.company.application.MainClass if run from any directory
D. java -classpath . Mainclass if run from the /apps/com/company/application directory
E. java -classpath /apps/com/company/application:. MainClass if run from the /apps
directory
F. java com.company.application.MainClass if run from the
/apps/com/company/application directory
Answer: B, C
QUESTION 163
Given:
310-055
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: A
QUESTION 164
A programmer has an algorithm that requires a java.util.List that provides an
efficient implementation of add(0, object), but does NOT need to support quick
random access.
What supports these requirements?
A. java.util.Queue
B. java.util.ArrayList
C. java.util.LinearList
D. java.util.LinkedList
Answer: D
QUESTION 165
Which 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 and
object inequality for that class.
B. The hashCode method is used by the java.util.SortedSet collection class to order the
elements within that set.
C. The hashCode method for a given class can be used to test for object inequality, but
NOT object equality for that class.
D. The only important characteristic of the values returned by a hashCode method is that
the distribution of valus must follow a Gaussian distribution.
E. The hashCode method is used by the java.util.HashSet collection class to group the
elements within that set into hash buckets for swift retrieval.
Answer: C, E
QUESTION 166
DRAG DROP
Given:
310-055
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");
list.add("two");
//System.out.println(((String)list.get(0)).length());
System.out.println((list.get(0)).length());
}}
Answer:
QUESTION 167
DRAG DROP
Given the class definitions:
310-055
Place the correct Compilation Result on each takeList() method definition to
indicate whether or not the go() method would compile given that definition.
Answer:
QUESTION 168
DRAG DROP
Place the code in the appropriate place such that this program will always output [1,
2].
Answer:
QUESTION 169
Given:
310-055
and:
A programmer iterates over the TreeSet and prints the name of each Drink object.
What is the result?
A. Tea
B. Coffe
C. Coffe
Tea
D. Compilation fails.
E. The code runs with no output
F. An exception is thrown at runtime
Answer: B
Explanation:
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);
310-055
for(Drink d : set){
System.out.println(d.name);
}
}
}
QUESTION 170
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: D
QUESTION 171
Given:
and:
Which exception or error should be thrown by the virtual machine?
A. StackOverflowError
B. NullPointerException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionInInitializerError
Answer: A
310-055
QUESTION 172
Given:
What is the result?
A. 6
B. 7
C. 10
D. 11
E. Compilation fails
F. An exception is thrown at runtime
Answer: E
QUESTION 173
Given:
What is the result?
A. three
B. other
C. An exception is thrown at runtime.
D. Compilation fails because of an error on line 12.
E. Compilation fails because of an error on line 13.
F. Compilation fails because of an error on line 15.
Answer: A
QUESTION 174
DRAG DROP
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 correct
solution.
310-055
Answer:
QUESTION 175
Given:
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() method
B. change line 7 to public synchronized void go() {
C. change the variable declaration on line 2 to private volatile int x;
D. wrap the code inside the foo() method with a synchronized( this ) block
E. wrap the loop code inside the go() method with a synchronized block synchronized(
this ) { // for loop code here }
Answer: A, D
QUESTION 176
DRAG DROP
Place the code elements in position so that the Flags2 class will compile and make
appropriate use of the wait/notify mechanism.
Note: You may reuse code elements.
310-055
Answer:
QUESTION 177
DRAG DROP
Given:
Assume that sleep(n) executes in exactly n milliseconds, and all other code execute in
an insignificant amount of time.
Place the fragments in the output area to show the result of running this code.
310-055
Answer:
QUESTION 178
Given:
What is the result?
A. Compilation fails.
B. An exception is throw at runtime
C. The code executes normally and prints "bar".
D. The code executes normally, but nothing prints.
Answer: C
QUESTION 179
Given:
foo
and bar are public references available to many other threads. foo refers to a
Thread 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 will
stop executing wait()?
A. foo.notify();
310-055
B. bar.notify();
C. foo.notifyAll();
D. Thread.notify();
E. bar.notifyAll();
F. Object.notify();
Answer: E
QUESTION 180
Given:
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 181
Which two statements are true? (Choose two)
A.An encapsulated,public class promoters 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 a programmer to change an implementation without
affecting outside code
Answer: A, D.
QUESTION 182
hat 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. }
310-055
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.4
B.5
C.8
D.9
E.Compilations fails.
F.An exception is thrown at runtime
G.It is impossible to determine for certain
Answer: D
QUESTION 183
DRAG DROP
Place the code fragments into position to produice the output:
true true false
Answer:
310-055
Explanation:
Here ,the while condition is verified by using,
while(scanner.next()) ---> this willnot return boolean.it should be used to move the
text 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 is
true.
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 the
boolean text.
In the else part, we should move to the next text in the pattern.For this, we
should use. Then only the search engine will move to the next text.
else{
scanner.next();
}
Title : Sun Certified Programmer for the Java 2
Platform, Standard Edition 5.0
Ver : 07.09.07
310-055
QUESTION 1
Given the code in the exhibit.
What is the result?
A. Compilation fails
B. An exception is thrown at runtime.
C. An instance of Forest is serialized.
D. An instance of Forest and an instance of Tree are both serialized.
Answer: B
QUESTION 2
Which code, inserted ay line 14, will allow this class to correctly serialized and
desterilize?
310-055
A. S. default ReadObject ( );
B. This = s.defaultReadObject ( );
C. Y = s. default ( ) ; x = s.readInt ( );
D. X = s. readInt; y = s. readInt ( );
Answer: D
QUESTION 3
Given the exhibit.
What is the result?
A. 0
B. 1
C. 4
D. Compilation fails
E. An exception is thrown at runtime
Answer: D
QUESTION 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-2004
B. The value of S is Dec 14, 2000
C. An exception is thrown at runtime
D. Compilation fails because of an error in line 13.
Answer: D
QUESTION 5
DRAG DROP
The doesFileExist method takes an array of directory names representing a path
from 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.
310-055
Answer:
Explanation:
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,String
filename){
String path = "";
for(String dir: directories){
path = path +File.separator+dir;
//path = path.getSubdirectory(dir);
}
System.out.println(path);
310-055
File file = new File(path,filename);
return file.exists();
}}
QUESTION 6
DRAG DROP
Given:
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:
QUESTION 7
When comparing java. Io. BufferedWriter to java.io.FileWriter, which capability
exist as a method in only one of the two?
A. closing the stream
B. flushing the stream
C. writing to the stream
D. marking a location in the stream
E. writing a line separator to the stream
Answer: E
QUESTION 8
Given the exhibit:
310-055
Which two code fragments, inserted independently at line 3, generate the output
4247? (choose two)
A. String s = "123456789"
S. = (s-"123").replace (1,3, "24") - "89";
B. StringBuffer s = new StringBuffer ("123456789");
S.delete (0,3) replace(1,3,"24"). Delete (4,6)
C. StringBuffer s = new StringBuffer ("123456789");
S.substring (3,6).delete(1,3). insert (1, "24").
D. StringBuilder s = new StringBuilder ("123456789");
S.substring (3,6) delete (1,2). insert (1, "24")
E. StringBuilder s = new StringBuilder ("123456789");
S.delete (0,3) replace(1,3,). Delete (2,5) insert (1, "24")
Answer: B,E
QUESTION 9
Which three statements concerning the use of the java . io. Realizable interface are
true? (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 and
deserialization
D. The values in field with the transient modifier will NOT survive serialization and
deserialization
E. It is legal to serialize an object of a type that has a supertype that does NOT implement
java .io.Serialization
Answer: B,D,E
QUESTION 10
Given the exhibit:
310-055
What is the result?
A. short Long
B. SHORT LONG
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
QUESTION 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's
date?
A. Local loc = Local.getLocal ( );
System.out printIn (loc.getDisplayCountry ( )
B. Local loc = Local.getDefault ( );
System.out printIn (loc.getDisplayCountry ( )
+ " " " +df. Format (d) );
C. Local loc = Local.getLocal ( );
System.out printIn (loc.getDisplayCountry ( )
+ " " +df. setDateFormat (d) ) ;
D. Local loc = Local.getDefault ( );
System.out printIn (loc.getDisplayCountry ( )
+ " " +df.seDateFormat (d) );
Answer: B
QUESTION 12
Given the exhibit:
310-055
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime
C. The code executes and prints " running"
D. The code executes and prints "runningrunning"
E. The code executes and prints "runningrunninigrunning
Answer: E
QUESTION 13
Exhibit:
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,
310-055
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,C
QUESTION 14
Given the exhibit:
Which statement is rue?
A. This code may throw an InterruptedException
B. This code may throw an IllegalStateExcepion
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. Reversing the order of obj.wait ( ) and obj. notify ( ) may vcause this method to
complete normally
Answer: B
QUESTION 15
Given the exhibit:
What can be a result?
310-055
A. Compilation fails
B. An exception is thrown at runtime
C. The code executes and prints "StartedComplete"
D. The code executes and prints "StartedComplete0123"
E. The code executes and prints "Started0123Complete"
Answer: E
QUESTION 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 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 ( ) {
310-055
synchronized (o) { /* code here */ }
}
Answer: C,E,F
QUESTION 18
Exhibit:
What is the result?
A. The code will deadlock
B. The code may run with no output
C. An exception is thrown at runtime
D. The code may run with output " 0 6 "
E. The code may run with output "2 0 6 4"
310-055
F. The code may run with output "0 2 4 6"
Answer: F
QUESTION 19
Given the exhibit:
What is the result?
A. Compilation fails
B. An exception is thrown at runtime
C. The code executes normally and prints "sleep"
D. The code executes normally, but nothing is printed.
Answer: C
QUESTION 20
Which two statements are true about has-a and is a relationships? (choose two)
A. Inheritance represents an is -a relationship
B. Inheritance represents a has-a relationship
C. Interfaces must be used when creating a has-a relationship
D. Instance variables can be used when creating a has-a relationship
Answer: A,D
QUESTION 21
Given the exhibit:
What can directly access and change the value of the variable name?
A. any class
B. only the Target class
C. any class in the Certkiller package
D. any class that extends Target
Answer: C
310-055
QUESTION 22
Which three statements are true? (choose three)
A. A final method in class x can be abstract if and only if X is abstract
B. 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 explicitly
referencing the class x.
F. A method with the same signature as a private final method in class X can be
implemented in a subclass of X.
Answer: B,E,F
QUESTION 23
DRAG DROP
Place the Types in one of the Type columns, and the Relationships in the
Relationship column, to define appropriate has-a and is-a relationships.
Answer:
310-055
QUESTION 24
DRAG DROP
Replace two of the Modifiers that appear in the Single class to make the code
compile.
Note: Three modifiers will not be used and four modifiers in the code will remain
unchanged.
Answer:
QUESTION 25
Exhibit:
310-055
What is the result?
A. Value is : 8
B. Compilation fails.
C. Value is : 12
D. Value is ; -12
E. The code runs with no output
F. An exception is thrown at runtime.
Answer: A
QUESTION 26
Given the exhibit:
310-055
Which statement is true?
A. The class is fully encapsulated
B. The code demonstrates polymorphism.
C. The ownerName variable breaks encapsulation
D. The CardID and limit variables break polymorphism
E. The setCardInformation method breaks encapsulation
Answer: C
QUESTION 27
Given the exhibit:
What is the result?
A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime
Answer: E
310-055
QUESTION 28
Exhibit:
What two must the programmer do to oerrect the compilation errors?
A. insert a call to this ( ) in the Car CONSTRUCTOR
B. insert a call to this ( ) in the MeGo constructor
C. insert a call to super ( ) in the MeGo constructor
D. insert a call to super (vin) in the MeGo constructor
E. change the wheel Count variable in CAR TO PROTECTED
F. CHANGE LINE 3 IN THE MeGo class to super wheel Count =3;
Answer: D,E
QUESTION 29
Given the exhibit:
What three code fragments inserted individually at line 15, make use of
polymorphism? (choose three)
310-055
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 30
Given the exhibit:
Which statement should be placed at line 14 to suggest that the virtual machine
expend effort toward recycling the memory used by the object Certkiller ?
A. System.gc ( )
B. Runtime. Gc ( )
C. System.freeMemory ( )
D. Runtime.getRuntime ( ) growHeap ( )
E. Runtime.getRuntime ( ) free Memory ( )
Answer: A
QUESTION 31
Exhibit:
310-055
What is the output of the program shown in the exhibit?
A. 300.100.100.100.100
B. 300.300.100.100.100
C. 300.300.300.100.100
D. 300.300.300.300.100
Answer: B
QUESTION 32
A developer is creating a class Book, that needs to acces class Paper. The Paper
class is deployed in a JAR named myLib.jar.
Which three, taken independently, will allow the developer to use the Paper class
while compiling the Book class? (choose three)
A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar
B. 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 set
that includes /foo/myLib.jar/Paper,Class.
D. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set
that includes /foo/myLib.jar.
E. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac
310-055
-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 33
Given the exhibit:
Which statement is true about the object referenced by snoog, smooch and booch
immediately after line 23 executes?
A. None of these objects are eligible for garbage collection
B. Only the object referenced by booch is eligible for garbage collection
C. Only the pbject referenced by snoog is eligible for garbage colletion
D. Only the object referenced by smooch is eligible for garbage collection
E. The objects referenced by smooch and booch are eligible for garbage collection
Answer: E
QUESTION 34
Given the exhibit:
310-055
and the command line invocation
java Certkiller 5 a b c
what is the result?
A. a b
B. b c
C. a b c
d. Compilation fails
C. An exception is thrown at runtime
Answer: B
QUESTION 35
Given the exhibit:
What is the result?
A. r, t, t
B. r, e, o,
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
QUESTION 36
Given the exhibit:
310-055
and the command line:
java - Drop.custom = gobstopper Certkiller
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,E
QUESTION 37
Given classes defined in two different files:
What is required at line 5 in class Certkiller App to use the process method of Bit Utils?
A. Process (bytes);
B. BitUtils.process (bytes);
C. Util.BitUtils.process (bytes);
D. Certkiller App cannot use methods in BitUtils
E. Import util.BitUtils.*; process (bytes);
Answer: C
QUESTION 38
Exhibit:
310-055
What is the outcome of the code?
A. Compilation fails.
B. Gobstopper
Fizzylifting
C. Gobstopper
Scremdiddlyumptious
D. Scrumdiddlyumptious
Fizzylifting
E. Scrumiddlyumptious
Scrumdiddlyumptious
Answer: B
QUESTION 39
Given classes defined in two different files
310-055
What is required at line 5 in class Certkiller Application to use the process method of
BitUtils?
A. PROCESS (BYTES);
B. BitUtils.process(bytes);
C. App.BitUtils.process (bytes)
D. Util.BitUtils. process (bytes)
E. Import util.BitUtils.*; process (bytes);
F. Certkiller Application cannot use the process method in BitUtils.
Answer: F
QUESTION 40
DRAG DROP
The image represents a complete package structure for a set of classes: "com" is the
beginning of the fully-qualified package name for all classes.
Give this package structure, insert the code needed to make the Car class compile
and runt successfully.
All three placeholds must be filled. If fewer than three statement are needed, use the
"// blank" options.
310-055
Answer:
QUESTION 41
Given the exhibit:
310-055
What is the result when this ode executed?
A. 1
B. 3
C. 123
D. 321
E. The code runs with no output
Answer: C
QUESTION 42
DRAG DROP
Place the code fragments in position to complete the Displayable interface.
Answer:
QUESTION 43
Given the exhibit:
310-055
Which code, inserted at line 14, allows the Sprite class to compile?
A. Direction d = NORTH
B. Certkiller .Direction d = NORTH
C. Direction d = Direction.NORTH
D. Certkiller .Direction d = Certkiller Direction. NORTH
Answer: D
QUESTION 44
Exhibit:
Which three statements are true? (Choose three)
A. Compilation fails
B. The code compiles and the output is 2
C. If lines 16, 17 and 18 were removed, compilation would fail.
D. If lines 24,25, and 26 were removed, compilation would fail.
E. If lines 16,17 and 18 were removed, the code would compile and the output would be
310-055
2.
F. If line 24,25 and 26 were removed, the code would compile and the output would be 1.
Answer: B,E,F
QUESTION 45
DRAG DROP
Add methods to the Beta class to make it compile correctly.
Answer:
QUESTION 46
Given the exhibit:
What is the output from line 5 of the Certkiller class?
310-055
A. 5
B. 10
C. 12
D. 17
E. 24
Answer: B
QUESTION 47
Given the exhibit:
Which two methods, inserted individually, correctly complete the Certkiller 3 class?
(choose two)
A. public void fooo ( ) { }
B. public int foo ( ) {return 3: }
C. public Certkiller 2 foo ( ) {return this;}
D. public Certkiller 1 foo ( ) {return this}
Answer: C,D
QUESTION 48
Exhibit:
310-055
What is the result?
A. snootchy 420 third second first
B. snootchy 420 first second third
C. first second third snootchy 420
D. third second first snootchy 420
E. thirds first second snootchy 420
F. first second first third snootchy 420
Answer: D
QUESTION 49
Given the exhibit:
What is the result?
A. 1 2 3
B. Compiltion fails because of an error in line 12.
C. Compilation fails because of an error in line 13
310-055
D. Compilation fails because of an error in line 14.
E. A ClassCastException is thrown at runtime
Answer: A
QUESTION 50
A Java Bean component has the following field:
11. PRIVATE BOOLEAN ENABLED:
Which two pairs of method declarations follow the JavaBean standard for accessing
this 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 ( )
Answer: A,C
QUESTION 51
Given the exhibit:
Which two statements are true? (choose two)
A. Certkiller .beta ( ) is a valid invocation of beta ( )
B. Certkiller .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 52
Given the exhibit:
310-055
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
QUESTION 53
Given the exhibit:
310-055
What is the result
A. B
B. The code exception is thrown at runtime
C. 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 54
Given the exhibit:
What is the result if NullPointerException occurs on line 34?
A. c
B. a
C. ab
D. ac
E. bc
F. abc
Answer: D
QUESTION 55
Given the exhibit:
310-055
Which exception or error will be thrown when a programmer attempts to run this
code?
A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitoatializerError
D. java.lang.ArrayIndexOutOfBoundsException
Answer: C
QUESTION 56
Exhibit:
Which two statements are truee if a NullPointerException is thrown on line 3 of
class C? (choose two)
310-055
A. The application will crash.
B. The code on line 29 will be executed
C. The code on line 5 of class A will execute.
D. The code on line 5 of class B will execute.
E. The exception will be propagated back to line 27.
Answer: B,E
QUESTION 57
Given the exhibit:
What is the result?
A. 0
B. 10
C. 12
D. Line 29 will never be reached.
Answer: C
QUESTION 58
Given the exhibit:
What is the result?
A. The value "4" is printed at the command line
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPOINTEReXCEPTION OCCURS AT RUNTIME.
E. A NumberFormatException occurs at runtime.
310-055
F. An IllegalStateException occurs at runtime.
Answer: D
QUESTION 59
Given the exhibit:
What is the result?
A. 3, 2, 1,
B. 1, 2, 3,
C. Compilation fails
D. The code runs with no output
E. An exception is thrown at runtime
Answer: C
QUESTION 60
Given the exhibit:
What is the result when method testIfA is invoked?
A. True
B. Not true
C. An exception is thrown at runtime
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
310-055
Answer: A
QUESTION 61
GIVEN THE EXHIBIT:
Which statement is true?
A. All of the assert statements are used appropriately.
B. Only the assert statement on line 31 is used appropriately
C. The assert statements on lines 29 and 31 are used appropriately
D. The assert statements on lines 26 and 29 are used appropriately
E. The assert statements on lines 29 and 33 are used appropriately
F. The assert statements on lines 29 ,31and 33 are used appropriately
G. The assert statements on lines 26,29 and 31 are used appropriately
Answer: C
310-055
QUESTION 62
GIVEN THE EXHIBIT:
What is the result?
A. null
B. zero
C. some
D. Compilation fails
E. An exception is thrown at runtime
Answer: D
QUESTION 63
Given the exhibit:
What is the result?
A. test
B. Exception
C. Compilation fails
D. NullPointerException
Answer: C
QUESTION 64
Given the exhibit:
310-055
What is the result?
A. Compilation fails
B. aAaA aAa AAaa AaA
C. AAaa AaA aAa aAaA
D. AaA AAaa aAaA aAa
E. aAa AaA aAaA AAaa
F. An exception is thrown at runtime
Answer: C
QUESTION 65
Given the exhibit:
What is the result?
A. 0
B. 1
C. 2
D. 3
E. 4
310-055
F. Compilation fails.
G. An exception is thrown at runtime
Answer: D
QUESTION 66
Given a pre-generics implementation of a method:
Which three changes must be made to the method sum to use generics? (choose
three)
A. remove line 14
B. 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 67
Given the exhibit:
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.
310-055
D. A ClassCastExceptation occurs in line 31.
E. The value of all four object prints in natural order.
Answer: C
QUESTION 68
DRAG DROP
Place the code into position to create a class that maps from Strings to integer
values.
The result of execution must be [one]. Some options may be used more than once.
Answer:
310-055
Explanation:
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 69
DRAG DROP
Place a result onto each motho call to indicate what would happen if the method call
were inserted at line 9. Note: Results can be used more than once.
310-055
Answer:
QUESTION 70
Given the exhibit:
What is the result?
A. apple:apple
B. carrot:apple
C. apple:banana
D. banana:apple
E. carrot:carrot
F. carrot:banana
Answer: C
310-055
QUESTION 71
Given :
A programmer is developing a class Key, that will be used as a key in a standard
java.util.HashMap.
Which two methods should be overridden to assure that key works correctly as a
key? (choose two)
A. public int hashCode ( )
B. public Boolean equals (Key k)
C. public int compareTo (object o
D. public Boolean equals (object o)
Answer: A,D
QUESTION 72
Given the exhibit:
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 73
Given the exhibit:
310-055
enumExample { ONE, TWO, THREE }
Which statement is true?
A. The expressions (ONE = = ONE) and ONE.equals (ONE) are both guaranteed to be
true.
B. The expression (ONE < TWO ) is guaranteed to be true and ONE.compareTo (TWO)
is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HasMap.; instead, the
programmer must use a java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT be
sorted because enumerated Type do NOT IMPLEMENT JAVA.LANG.Comparable.
Answer: A
QUESTION 74
Given:
Which line of code marks the earliest point that an object referenced by intObj
becomes a candidate for garbage collection?
A. Line 16
B. Line 17
C. Line 18
D. Line 19
E. The object is NOT a candidate for garbage collection.
Answer: D
QUESTION 75
Given:
andthe command line invocation:
javaYippee2 a b c
What is the result?
310-055
A. a b
B. b c
C. a b c
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: B
QUESTION 76
A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants
to execute the main method of Poker on a UNIX system using the command:
Java games.cards.Poker
What allows the user to do this?
A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java
B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include
/stuff/java/*.jar
C. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include
/stuff/java/Poker.jar
D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include
/stuff/java
E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include
/stuff/java/*.jar
F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include
/stuff/java/Poker.jar
Answer: C
QUESTION 77
Exhibit:
310-055
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 );
Answer: B, C, F
QUESTION 78
Given a class Repetition:
And given another class Demo:
310-055
Which code should be inserted at line 1 of Demo.java to compile and run Demo to
print "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
QUESTION 79
Given:
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 80
Exhibit:
310-055
Given the fully-qualified class names:
com.foo.bar.Dog
com.foo.bar.blatz.Book
com.bar.Car
com.bar.blatz.Sun
Which graph represents the correct directory structure for a JAR file from which
those classes can be used by the compiler and JVM?
A. Jar A
B. Jar B
C. Jar C
D. Jar D
E. Jar E
Answer: A
QUESTION 81
Given:
and two separate command line invocations:
310-055
java Yippee
java 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
QUESTION 82
Given:
What is the result?
A. Compilation fails
B. An exception is thrown at runtime
C. doStuff x = 6 main x = 6
D. doStuff x = 5 main x = 5
E. doStuff x = 5 main x = 6
F. doStuff x = 6 main x = 5
Answer: D
QUESTION 83
Given:
310-055
When the doSomething method is called, after which line does the Object created in
line 5 bbecome available for garbage collection?
A. Line 5
B. Line 6
C. Line 7
D. Line 8
E. Line 9
F. Line 10
Answer: D
QUESTION 84
Given:
What is the result?
A. Exception
B. A, B, Exception
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 14.
E. A NullPointerException is thrown at runtime.
Answer: D
QUESTION 85
Given:
310-055
What is the result?
A. harrier
B. shepherd
C. retriever
D. Compilation fails
E. retriever harrier
F. An exception is thrown at runtime.
Answer: D
QUESTION 86
Given:
What is the result?
A. A, B, C
B. B, C, A
C. Compilation fails
D. The code runs with no output
E. An exception is thrown at runtime
Answer: B
QUESTION 87
Given:
310-055
What is the result?
A. end
B. Compilation fails
C. exception end
D. exception test end
E. A Throwable is thrown by main
F. An Exception is thrown by main
Answer: E
QUESTION 88
Given:
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: B, C, E
QUESTION 89
Given:
310-055
What is the result?
A. Compilation fails
B. pi is bigger than 3.
C. An exception occurs at runtime.
D. pi is bigger than 3. Have a nice day.
E. pi is not bigger than 3. Have a nice day.
Answer: A
QUESTION 90
Given:
Which code, inserted at line 16 will cause a java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f = (Delta)x;
C. Foo f = (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Answer: B
QUESTION 91
Given a method that must ensure that its parameter is not null:
310-055
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 92
DRAG DROP
Place the correct Code in the Code Sample to achieve the expected results.
Expected results:
Output: 1 2 4 8 16 32
Code Sample
Answer:
QUESTION 93
Given:
310-055
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2
F. java -ea:test test file1
Answer: B, E
QUESTION 94
Given:
Which statement is true if a ResourceException is thrown on line 86?
A. Line 92 will not execute.
B. The connection will not be retrieved in line 85.
C. The resource connection will not be closed on line 88.
D. The enclosing method will throw an exception to its caller.
Answer: C
QUESTION 95
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly
use Java serialization and given:
310-055
What is the result?
A. restore 400
B. restore 403
C. restore 453
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: C
QUESTION 96
Given:
What is the result?
A. Compilation fails
B. Pi is approximately 3.
C. Pi is approximately 3.141593.
D. An exception is thrown at runtime.
Answer: D
QUESTION 97
Given:
What is the result?
310-055
A. int Long
B. Short Long
C. Compilation fails
D. An exception is thrown at runtime.
Answer: A
QUESTION 98
DRAG DROP
Chain these constructors to create objects to read from a file named "in" and to
write to a file named "out".
Answer:
Explanation:
Sample code:
import java.io.*;
public class Files {
public static void main(String []args){
try{
BufferedReader reader = new BufferedReader(new
FileReader("in"));
PrintWriter writer = new PrintWriter(new BufferedWriter(new
FileWriter("out")));
} catch (Exception ex){
System.out.println("Exception!!");
} }
}
QUESTION 99
DRAG DROP
Place the code fragments into position to use a BufferedReader to read in an entire
text file.
310-055
Answer:
QUESTION 100
Given this method in a class:
Which statement is true?
A. This code is NOT thread-safe.
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform poorly. For better performance, the code should be rewritten:
return "<" + this.name + ">";
310-055
D. This code will perform well and converting the code to use StringBuilder will not
enhance the performance.
Answer: B
QUESTION 101
Given:
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
QUESTION 102
Given:
Which two statements are true about the result if the locale is Locale.US? (Choose
two.)
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.
310-055
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 103
DRAG DROP
Place the correct description of the compiler output on the code fragment to be
inserted at line 4 and 5. The same compiler output may be used more than once.
Answer:
QUESTION 104
Given:
Which three will compile successfully? (Choose three.)
310-055
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 105
Exhibit:
Which statement is true about the set variable on line 12?
A. The set variable contains all six elements from the coll collection, and the order is
guaranteed to be preserved.
B. The set variable contains only three elements from the coll collection, and the order is
guaranteed to be preserved.
C. The set variable contains all six elements from the coll collection, but the order is
NOT guaranteed to be preserved.
D. The set variable contains only three elements from the coll collection, but the order is
NOT guaranteed to be preserved.
Answer: D
QUESTION 106
Given:
310-055
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: B
QUESTION 107
Given:
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: A
QUESTION 108
Given:
310-055
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 109
Given:
What, inserted at line 39, will sort the keys in the props HashMap?
A. Array.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s = new SortedSet(s);
Answer: B
QUESTION 110
DRAG DROP
Place code into the class so that it compiles and generates the output answer=42.
Note: Code options may be used more than once.
310-055
Answer:
QUESTION 111
DRAG DROP
Given:
Place the Compilation Results on each code statement to indicate whether or not
that code will compile if inserted into the takeList() method.
Answer:
QUESTION 112
Which two code fragments will execute the method doStuff() in a separate thread?
(Choose two.)
A. new Thread() {
public void run() { doStuff() ;}
310-055
};
B. new Thread() {
public void start() { doStuff(); }
};
C. new Thread() {
public void start() { doStuff(); }
}.run();
D. new Thread() {
public void run() { doStuff(); }
}.start();
E. new Thread(new runnable() {
public void run() { doStuff(); }
}).run();
F. new Thread(new runnable() {
public void run() { doStuff(); }
}).start();
Answer: D, F
QUESTION 113
Given:
Which to can be results? (Choose two.)
A. java.lang.RuntimeException: Problem
B. run.
java.lang.RuntimeException: Problem
C. End of method.
java.lang.RuntimeException: Problem
D. End of method.
run.
java.lang.RuntimeException: Problem
E. run.
java.lang.RuntimeException: Problem
End of method
Answer: D, E
310-055
QUESTION 114
Given:
Which three changes should be made to adapt this class to be used safely by
multiple threads? (Choose three.)
A. declare reset() using the synchronized keyword
B. declare getName() using the synchronized keyword
C. declare getCount() using the synchronized keyword
D. declare the constructor using the synchronized keyword
E. declare increment() using the synchronized keyword
Answer: A, C, E
QUESTION 115
Given:
Which statement is true?
A. Compilation fails
B. 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.
Answer: E
310-055
QUESTION 116
Given:
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: B
QUESTION 117
Given:
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 118
DRAG DROP
Place the Output Options in the Actual Output Sequence to indicate the output
from this code:
310-055
Answer:
QUESTION 119
Given:
What is the result?
A. 0 . 0
B. Compilation fails.
C. A ParseException is thrown by the parse method at runtime.
D. A NumberFormatException is thrown by the parse method at runtime.
Answer: B
310-055
QUESTION 120
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 121
Given:
Which code, inserted at line 15, creates an instance of the Point class defined in
Line?
A. Point p = new Point();
B. Line.Point p = new Line.Point();
C. The Point class cannot be instatiated at line 15.
D. Line l = new Line() ; l.Point p = new l.Point();
Answer: B
310-055
QUESTION 122
Given:
Which statement is true?
A. The code will compile without changes.
B. The code will compile if public Tree() { Plant(); } is added to the Tree class.
C. The code will compile if public Plant() { Tree(); } is added to the Plant class.
D. The code will compile if public Plant() { this("fern"); } is added to the Plant class.
E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class.
Answer: D
310-055
QUESTION 123
Given:
Which two code fragments, inserted independently at line 12, will allow the class to
compile? (Choose two.)
A. foreach( x ) System.out.println(z);
B. for( int z : x ) System.out.println(z);
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 124
Exhibit:
Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
D. Compilation of class AImpl will fail because of an error in line 2.
Answer: C
QUESTION 125
DRAG DROP
Place the lines in the correct order to complete the enum.
enumElement {
310-055
Answer:
Explanation:
Code:
enum enumElement {
EARTH,WIND,FIRE {
public String info(){
return "Hot";
}
}
};
public String info(){
return "element";
}
QUESTION 126
DRAG DROP
Place the code elements in order so that the resulting Java source file will compile
correctly, resulting in a class called com.sun.cert.AddressBook.
310-055
Answer:
QUESTION 127
Which two classes correctly implement both the java.lang.Runnable and the
java.lang.Clonable interfaces? (Choose two.)
A. public class Session
implements Runnable, Clonable {
public void run();
public Object clone();
}
B. public class Session
extends Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
}
C. public class Session
implements Runnable, Clonable {
public void run() {/*do something*/}
public Object clone() {/*make a copy*/}
310-055
}
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 128
Given:
Which statement is true?
A. 420 is the output
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier.
E. Constructors CANNOT use the protected modifier.
Answer: A
QUESTION 129
Given:
What is the result?
A. foofoofoofoofoo
310-055
B. foobarfoobarbar
C. foobarfoofoofoo
D. foobarfoobarfoo
E. barbarbarbarbar
F. foofoofoobarbar
G. foofoofoobarfoo
Answer: D
QUESTION 130
Which 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 131
Given:
Which statement is true about the class of an object that can reference the variable
base?
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.
Answer: C
QUESTION 132
DRAG DROP
Given:
310-055
Place the names "A" and "B" in the following output.
Answer:
QUESTION 133
Given:
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()
310-055
defined in line 9.
Answer: F
QUESTION 134
Which 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 135
DRAG DROP
Place the Relations on their corresponding Implementation Structures.
Note: Not all Implementation Structres will be used.
Answer:
QUESTION 136
Given:
310-055
And:
What is the result?
A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime.
Answer: C
QUESTION 137
Given:
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);}
310-055
Answer: C, D
QUESTION 138
Given:
What is the result when the programmer attempts to compile the code and run it
with the command java Converter 12?
A. It is true that j= =i.
B. It is false that J= =i.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 13.
Answer: D
QUESTION 139
Given:
What is the output?
A. 42
B. 420
C. 462
D. 42042
E. Compilation fails
F. An exception is thrown at runtime.
Answer: D
QUESTION 140
Assuming that the serializeBanana2() and the deserializeBanana2() methods will
correctly use Java serialization and given:
310-055
What is the result?
A. Compilation fails
B. 1 restored 42
C. 12 restored 42
D. 121 restored 42
E. 1212 restored 42
F. An exception is thrown at runtime
Answer: D
QUESTION 141
Given:
What is the result?
A. a b c
B. 1 2 3
C. a1b2c3
D. a1 b2 c3
E. Compilation fails
F. The code runs with no output.
G. An exception is thrown at runtime.
Answer: A
QUESTION 142
Given:
What is the result?
310-055
A. Compilation fails
B. After line 15, the value of age is 5.
C. After line 15, the value of age is 3.
D. An exception is thrown at runtime.
Answer: D
QUESTION 143
Given a valid DateFormat object named df, and
What updates d's value with the date represented by ds?
A. A
B. B
C. C
D. D
Answer: C
QUESTION 144
DRAG DROP
Place the Fragments into the program, so that the program will get lines from a text
file, display them, and then close all the resources.
310-055
Answer:
QUESTION 145
Given:
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 146
Given:
310-055
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 147
Given:
And:
What is the result?
A. Compilation fails.
B. Cannot add Toppings
C. The code runs with no output.
D. A NullPointerException is thrown in Line 4.
Answer: A
310-055
QUESTION 148
DRAG DROP
Insert six modifiers into the code such that it meets all of these requirements:
Answer:
QUESTION 149
Given:
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 150
A programmer needs to create a logging method that can accept an arbitrary
number of arguments. For example, it may be called in these ways:
310-055
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 151
Exhibit:
What is the result?
A. 4321
B. 0000
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 18.
Answer: D
Explanation: Compilation fails because of an error in line 18) constructor Person()
must be present in class Person for the compilation to succeed.
QUESTION 152
Given:
310-055
Which code inserted at line 14 causes the foo method to print RED, GREEN, and
BLUE?
A. for( Color c : Color.values() )
B. for( Color c = RED; c<= BLUE; c++ )
C. for( Color c ; c.hasNext() ; c.next() )
D. for( Color c = Color[0]; c <= Color[2]; c++)
E. for( Color c = Color.RED; c <= Color.BLUE; c++)
Answer: A
QUESTION 153
Exhibit:
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 154
Given:
Which three methods, inserted individually at line 14, will correctly complete class
Two? ( Choose three.)
310-055
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 155
Given:
A programmer wants to create an interface called B that has A as its parent.
Which interface declaration is correct?
A. public interface B extends A {}
B. public interface B implements A {}
C. public interface B instanceOf A {}
D. public interface B inheritsFrom A {}
Answer: A
QUESTION 156
Given:
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();
310-055
D. Shape s = new Circle();
s->setAnchor(10,10);
s->draw();
E. Circle c = new Circle();
c.Shape.setAnchor(10,10);
c.shape.draw();
Answer: C
QUESTION 157
Given:
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 158
Which two code fragments correctly create and initialize a static array of int
elements? (Choose two.)
A. static final int[] a = { 100,200 };
B. static final int [] a;
310-055
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 159
A UNIX user named Bob wants to replace his chess program with a new one, but he
is not sure where the old one is installed. Bob is currently able to run a Java chess
program starting from his home directory /home/bob using the command:
Java -classpath /test:/home/bob/downloads/*.jar games.Chess
Bob's CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar
What is a possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. 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 160
Given:
What is the result?
A. s 14
B. s 16
C. s 10
D. Compilation fails
E. An exception is thrown at runtime.
Answer: B
310-055
QUESTION 161
Given:
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 162
Given:
And MainClass exists in the /apps/com/company/application directory. Assume the
CLASSPATH 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 directory
B. java com.company.application.MainClass if run from the /apps directory
C. java -classpath /apps com.company.application.MainClass if run from any directory
D. java -classpath . Mainclass if run from the /apps/com/company/application directory
E. java -classpath /apps/com/company/application:. MainClass if run from the /apps
directory
F. java com.company.application.MainClass if run from the
/apps/com/company/application directory
Answer: B, C
QUESTION 163
Given:
310-055
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: A
QUESTION 164
A programmer has an algorithm that requires a java.util.List that provides an
efficient implementation of add(0, object), but does NOT need to support quick
random access.
What supports these requirements?
A. java.util.Queue
B. java.util.ArrayList
C. java.util.LinearList
D. java.util.LinkedList
Answer: D
QUESTION 165
Which 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 and
object inequality for that class.
B. The hashCode method is used by the java.util.SortedSet collection class to order the
elements within that set.
C. The hashCode method for a given class can be used to test for object inequality, but
NOT object equality for that class.
D. The only important characteristic of the values returned by a hashCode method is that
the distribution of valus must follow a Gaussian distribution.
E. The hashCode method is used by the java.util.HashSet collection class to group the
elements within that set into hash buckets for swift retrieval.
Answer: C, E
QUESTION 166
DRAG DROP
Given:
310-055
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");
list.add("two");
//System.out.println(((String)list.get(0)).length());
System.out.println((list.get(0)).length());
}}
Answer:
QUESTION 167
DRAG DROP
Given the class definitions:
310-055
Place the correct Compilation Result on each takeList() method definition to
indicate whether or not the go() method would compile given that definition.
Answer:
QUESTION 168
DRAG DROP
Place the code in the appropriate place such that this program will always output [1,
2].
Answer:
QUESTION 169
Given:
310-055
and:
A programmer iterates over the TreeSet and prints the name of each Drink object.
What is the result?
A. Tea
B. Coffe
C. Coffe
Tea
D. Compilation fails.
E. The code runs with no output
F. An exception is thrown at runtime
Answer: B
Explanation:
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);
310-055
for(Drink d : set){
System.out.println(d.name);
}
}
}
QUESTION 170
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: D
QUESTION 171
Given:
and:
Which exception or error should be thrown by the virtual machine?
A. StackOverflowError
B. NullPointerException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionInInitializerError
Answer: A
310-055
QUESTION 172
Given:
What is the result?
A. 6
B. 7
C. 10
D. 11
E. Compilation fails
F. An exception is thrown at runtime
Answer: E
QUESTION 173
Given:
What is the result?
A. three
B. other
C. An exception is thrown at runtime.
D. Compilation fails because of an error on line 12.
E. Compilation fails because of an error on line 13.
F. Compilation fails because of an error on line 15.
Answer: A
QUESTION 174
DRAG DROP
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 correct
solution.
310-055
Answer:
QUESTION 175
Given:
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() method
B. change line 7 to public synchronized void go() {
C. change the variable declaration on line 2 to private volatile int x;
D. wrap the code inside the foo() method with a synchronized( this ) block
E. wrap the loop code inside the go() method with a synchronized block synchronized(
this ) { // for loop code here }
Answer: A, D
QUESTION 176
DRAG DROP
Place the code elements in position so that the Flags2 class will compile and make
appropriate use of the wait/notify mechanism.
Note: You may reuse code elements.
310-055
Answer:
QUESTION 177
DRAG DROP
Given:
Assume that sleep(n) executes in exactly n milliseconds, and all other code execute in
an insignificant amount of time.
Place the fragments in the output area to show the result of running this code.
310-055
Answer:
QUESTION 178
Given:
What is the result?
A. Compilation fails.
B. An exception is throw at runtime
C. The code executes normally and prints "bar".
D. The code executes normally, but nothing prints.
Answer: C
QUESTION 179
Given:
foo
and bar are public references available to many other threads. foo refers to a
Thread 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 will
stop executing wait()?
A. foo.notify();
310-055
B. bar.notify();
C. foo.notifyAll();
D. Thread.notify();
E. bar.notifyAll();
F. Object.notify();
Answer: E
QUESTION 180
Given:
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 181
Which two statements are true? (Choose two)
A.An encapsulated,public class promoters 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 a programmer to change an implementation without
affecting outside code
Answer: A, D.
QUESTION 182
hat 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. }
310-055
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.4
B.5
C.8
D.9
E.Compilations fails.
F.An exception is thrown at runtime
G.It is impossible to determine for certain
Answer: D
QUESTION 183
DRAG DROP
Place the code fragments into position to produice the output:
true true false
Answer:
310-055
Explanation:
Here ,the while condition is verified by using,
while(scanner.next()) ---> this willnot return boolean.it should be used to move the
text 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 is
true.
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 the
boolean text.
In the else part, we should move to the next text in the pattern.For this, we
should use. Then only the search engine will move to the next text.
else{
scanner.next();
}
No comments:
Post a Comment