Question
Question
(ct) MasterExam3
Q1: Keywords 1
Which two are keywords? (Choose two.)
A. method
B. Long
C. throw
D. finalize
E. case
Hint: Which keywords are capitalized?
Reference: Chapter 1: Keywords
Objective: Java Programming Language Keywords (Objective 4.4)
Q2: Keywords 2
6. Which one will legally declare, construct, and initialize an array? (Choose one.)
A. int x [] = (1,0,2,0);
B. int [] a = new array(3);
C. int [4] x;
D. int array [] = new int [4];
E. int a [] = new int(4);
F. array a = new int{1,2,3};
Hint: Arrays use [], and array isn't a keyword.
Reference: Chapter 1: Legal and illegal array assignments
Objective: Array construction and initialization (Objective 1.1)
10. Which of the following is the most restrictive access modifier that allows a class to
have access to members of another class in the same package? (Choose one.)
A. public
B. static
C. private
D. protected
E. default access
Hint: Think about the order of restrictiveness.
Reference: Chapter 2: Class Declarations and Modifiers
Objective: Declarations and Modifiers (Objective 1.2)
Q11. Import
12. Which two are valid declarations within an interface? (Choose two.)
A. protected boolean logic = true;
B. abstract short timer = 22;
C. long haul = 23;
D. double [] moveIt(short stack);
E. public static void doMore(long tooth);
F. boolean final doMore(short change);
Hint: Remember the defaults.
Reference: Chapter 2: Declaring an Interface
Objective: Declarations (Objective 4.1)
13. Which is the required declaration in a class that implements the java.lang.Runnable
interface?
A. static run()
B. static start()
C. public void run()
D. public void start()
E. void run()
F. void start()
Hint: Remember what happens to a thread when this method ends.
Reference: Chapter 2: Declaring an Interface and Chapter 9 Threads
Objective: Declarations (Objective 4.1)
Q17: Shifting
Q18: Operators 2
Q23: Switch 2
Q25: Loops 3
Q26: Exceptions 1
26. Given the following,
1. public class Test {
2. public static void main(String [] args) {
3. try {
4. m1();
5. m2();
6. } catch (Exception e1) {
7. System.out.print(" except ");
8. }
9. }
10.
11. static void m1() throws Exception {
12. try {
13. throw new Exception();
14. } catch (Exception e2) {
15. System.out.print(" m1catch ");
16. }
17. }
18. static void m2() throws Exception {
19. try {
20. throw new Exception();
21. } finally {
22. System.out.print(" m2finally ");
23. }
24. }
25. }
Q27: Exceptions 2
Q28: Assert 1
Q30: Encapsulate 1
Q31: IS-A 1
31. Given the following,
1.
2. class Wings { }
3. interface Raptor extends Bird {
4. int size = 5;
5. }
6. abstract class Hawk implements Raptor {
7. private int name;
8. void hunt() { ; }
9. }
10. interface Bird {
11. Wings w = new Wings();
12. }
which is true about instances of the classes listed above?
A. Hawk has-a Wings
B. Wings is-a Raptor
C. Class Hawk has two instance variables
D. Concrete subclasses of Hawk must implement a hunt( ) method
Hint: How far does inheritance go?
Reference: Chapter 5: IS-A , HAS-A
Objective: IS-A / HAS-A (Objective 6.1)
Q32: OverXing 1
Q33: OverXing 2
Q34: Constructor 1
Q35: Constructor 2
Q36: Returns 1
Q37: Returns 2
Q39: String 2
Q40: Round
Q41: Degrees
41. Given that the cosine of 57 degrees is equal to the sine of 33 degrees, which of the
following two lines would be roughly equal?
A. Math.sin(33);
B. Math.cos(57);
C. Math.toDegrees(Math.sin(33));
D. Math.toDegrees(Math.cos(57));
E. Math.sin(Math.toRadians(33));
F. Math.cos(Math.toRadians(57));
Hint: What do the trig functions expect?
Reference: Chapter 6: Math methods
Objective: Math class (Objective 8.1)
Q42: Wrapper1
Q43: Wrapper 2
Q44: Equals 1
Q45: Equals 2
45. If x and y are reference variables for wrapper objects, which statement is true
A. If x.equals(y) is true then x == y must be true.
B. If x.equals(y) is false then x == y may be true.
C. If x.equals(y) is true then x == y may be false.
D. If x.equals(y) is true then x and y may be of different classes.
E. If x == y is false then x.equals(y) must be false.
Hint: Have the wrapper class's equals() methods been overridden?
Reference: Chapter 6: equals( )
Objective: equals( ) (Objective 5.2)
Q47: Hashcode 2
2. If the hashCode() method has been overridden, what other method must be overridden?
A. notify()
B. finalize()
C. toString()
D. equals()
E. clone()
Hint: Remember the hashcode contract.
Reference: Chapter 7: Overriding hashcode( )
Objective: hashcode (Objective 9.2)
Q48: Collection 1
48. Which of these collection classes allows you to access its elements in a predetermined
order, and assures you that there will be no duplicated elements in the collection?
A.) java.util.Vector
B.) java.util.TreeSet
C.) java.util.TreeMap
D.) java.util.LinkedList
E.) java.util.ArrayList
F.) java.util.HashSet
Hint: Which interfaces provide which capabilities?
Reference: Chapter 7: collections
Objective: Collections (Objective 9.1)
Q49: Collection 2
49. Which of these collection classes is the best suited to implement a stack, and does not
have the overhead of synchronized methods?
A. java.util.TreeMap
B. java.util.TreeSet
C. java.util.LinkedList
D. java.util.Vector
E. java.util.LinkedHashMap
Hint: What defines a list, a set, or a map?
Reference: Chapter 7: collections
Objective: Collections (Objective 9.1)
Q50: GC 1
Q51: GC 2
Q52: GC 3
52. Given the following, and that class X looks like this: class X { }
12. void doSomething() {
13. X x = doStuff( new X() );
14. X y = doStuff(x);
15. x = null;
16. y = null;
17. }
18. X doStuff(X mx) {
19. return doStuff2(mx);
20. }
21. X doStuff2(X m2) {
22. X z = new X();
22. return z;
20. }
at what point is the object created in line 13 eligible for garbage collection?
A. After line 13 runs
B. After line 14 runs
C. After line 15 runs
D. After line 16 runs
E. The object is not eligible.
F. It is not possible to know for sure.
Hint: Any reference variables left?
Reference: Chapter 7: garbage collection
Objective: GC (Objectives 3.1, 3.2, 3.3)
Q55: Anon 1
Q56: Anon 2
Q58: Anon 3
Q61: Thread 3
Q62: Thread 4
62. Which two do not cause a thread to stop being the currently running thread? (Choose
two.)
A. Calling the join() method on a live thread
B. Calling the sleep() method.
C. Calling the wait() method.
D. Calling the notify() method.
E. Entering an unlocked, synchronized block of code.
Hint: Who is making the call?
Reference: Chapter 9: Threads
Objective: Stopping threads (Objective 7.2)
Q63: Thread 5
Q64: Locks
Q65: Wait/Notify2
64. (should be 65) Which two statements are true? (Choose two.)
A. The notify() method can take a thread argument.
B. The wait() method causes another thread to stop executing.
C. The wait() method can take a long argument.
D. The wait() method can be called from a non-synchronized context.
E. The notify() method does not release an object's lock.
Hint: How do wait and notify work with separate threads?
Reference: Chapter 9: Preventing Execution
Objective: Threads (Objective 7.4)