Appendix F. Mock Exam


This is a mock exam for the Sun Certified Programmer for the Java 2 Platform (SCPJ2 1.4). It comprises brand new questions, which are similar to the questions that can be expected on the real exam. Working through this exam will give the reader a good indication of how well she is prepared for the real exam, and whether any topics need further study.

Q1

Given the following class, which statements can be inserted at position 1 without causing a compilation error?

 public class Q6db8 {     int a;     int b = 0;     static int c;     public void m() {         int d;         int e = 0;         // Position 1     } } 

Select the four correct answers.

  1. a++;

  2. b++;

  3. c++;

  4. d++;

  5. e++;

Q2

Which statements are true about the effect of the >> and >>> operators?

Select the three correct answers.

  1. For non-negative values of the left operand, the >> and >>> operators will have the same effect.

  2. The result of (-1 >> 1) is 0.

  3. The result of (-1 >>> 1) is “1.

  4. The value returned by >>> will never be negative if the left operand is non-negative.

  5. When using the >> operator, the left-most bit of the resulting value will always have the same bit value as the left-most bit of the left operand.

Q3

What is wrong with the following code?

 class MyException extends Exception {} public class Qb4ab {     public void foo() {         try {             bar();         } finally {             baz();         } catch (MyException e) {}     }     public void bar() throws MyException {         throw new MyException();     }     public void baz() throws RuntimeException {         throw new RuntimeException();     } } 

Select the one correct answer.

  1. Since the method foo() does not catch the exception generated by the method baz() , it must declare the RuntimeException in a throws clause.

  2. A try block cannot be followed by both a catch and a finally block.

  3. An empty catch block is not allowed.

  4. A catch block cannot follow a finally block.

  5. A finally block must always follow one or more catch blocks.

Q4

What will be written to the standard output when the following program is run?

 public class Qd803 {     public static void main(String[] args) {         String word = "restructure";         System.out.println(word.substring(2, 3));     } } 

Select the one correct answer.

  1. est

  2. es

  3. str

  4. st

  5. s

Q5

Given that a static method doIt() in the class Work represents work to be done, which block of code will succeed in starting a new thread that will do the work?

Select the one correct answer.

  1.  Runnable r = new Runnable() {     public void run() {         Work.doIt();     } }; Thread t = new Thread(r); t.start(); 
  2.  Thread t = new Thread() {     public void start() {         Work.doIt();     } }; t.start(); 
  3.  Runnable r = new Runnable() {     public void run() {         Work.doIt();     } }; r.start(); 
  4.  Thread t = new Thread(new Work()); t.start(); 
  5.  Runnable t = new Runnable() {     public void run() {         Work.doIt();     } }; t.run(); 
Q6

What will be printed when the following program is run?

 public class Q8929 {     public static void main(String[] args) {         for (int i=12; i>0; i-=3)             System.out.print(i);         System.out.println("");     } } 

Select the one correct answer.

  1. 12

  2. 129630

  3. 12963

  4. 36912

  5. None of the above.

Q7

What will be the result of attempting to compile and run the following code?

 public class Q275d {     static int a;     int b;     public Q275d() {         int c;         c = a;         a++;         b += c;     }     public static void main(String[] args) {         new Q275d();     } } 

Select the one correct answer.

  1. The code will fail to compile since the constructor is trying to access static members .

  2. The code will fail to compile since the constructor is trying to use static field a before it has been initialized .

  3. The code will fail to compile since the constructor is trying to use field b before it has been initialized.

  4. The code will fail to compile since the constructor is trying to use local variable c before it has been initialized.

  5. The code will compile and run without any problems.

Q8

What will be written to the standard output when the following program is run?

 public class Q63e3 {     public static void main(String[] args) {         System.out.println(9 ^ 2);     } } 

Select the one correct answer.

  1. 81

  2. 7

  3. 11

  4. false

Q9

Which statements is true about the compilation and execution of the following program with assertions enabled?

 public class Qf1e3 {     String s1;     String s2 = "hello";     String s3;     Qf1e3() {         s1 = "hello";     }     public static void main(String[] args) {         (new Qf1e3()).f();     }     {         s3 = "hello";     }     void f() {         String s4 = "hello";         String s5 = new String("hello");         assert(s1.equals(s2)); // (1)         assert(s2.equals(s3)); // (2)         assert(s3 == s4);      // (3)         assert(s4 == s5);      // (4)     } } 

Select the one correct answer.

  1. The compilation will fail.

  2. The assertion on the line marked (1) will fail.

  3. The assertion on the line marked (2) will fail.

  4. The assertion on the line marked (3) will fail.

  5. The assertion on the line marked (4) will fail.

  6. The program will run without any errors.

Q10

Which declarations of the main() method are valid in order to start the execution of an application?

Select the two correct answers.

  1. public void main(String args[])

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

  3. public static main(String[] argv)

  4. final public static void main(String [] array)

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

Q11

Under which circumstance will a thread stop?

Select the one correct answer.

  1. The run() method that the thread is executing ends.

  2. The call to the start() method of the Thread object returns.

  3. The suspend() method is called on the Thread object.

  4. The wait () method is called on the Thread object.

Q12

When creating a class that associates a set of keys with a set of values, which of these interfaces is most applicable ?

Select the one correct answer.

  1. Collection

  2. Set

  3. SortedSet

  4. Map

Q13

What is the result of running the following code with assertions enabled?

 public class Q1eec {     static void test(int i) {         int j = i/2;         int k = i >>> 1;         assert j == k : i;     }     public static void main(String[] args) {         test(0);         test(2);         test(-2);         test(1001);         test(-1001);     } } 

Select the one correct answer.

  1. The program executes normally and produces no output.

  2. An AssertionError with as message is thrown.

  3. An AssertionError with 2 as message is thrown.

  4. An AssertionError with -2 as message is thrown.

  5. An AssertionError with 1001 as message is thrown.

  6. An AssertionError with -1001 as message is thrown.

Q14

What will be written to the standard output when the following program is run?

 class Base {     int i;     Base() { add(1); }     void add(int v) { i += v; }     void print() { System.out.println(i); } } class Extension extends Base {     Extension() { add(2); }     void add(int v) { i += v*2; } } public class Qd073 {     public static void main(String[] args) {         bogo(new Extension());     }     static void bogo(Base b) {         b.add(8);         b.print();     } } 

Select the one correct answer.

  1. 9

  2. 18

  3. 20

  4. 21

  5. 22

Q15

Which declarations of a native method are valid in the declaration of the following class?

 public class Qf575 {     // Insert declaration of a native method here } 

Select the two correct answers.

  1. native public void setTemperature(int kelvin);

  2. private native void setTemperature(int kelvin);

  3. protected int native getTemperature();

  4. public abstract native void setTemperature(int kelvin);

  5. native int setTemperature(int kelvin) {}

Q16

Which collection implementation is suitable for maintaining an ordered sequence of objects, when objects are frequently inserted and removed from the middle of the sequence?

Select the one correct answer.

  1. TreeMap

  2. HashSet

  3. Vector

  4. LinkedList

  5. ArrayList

Q17

Which statements can be inserted at the indicated position in the following code to make the program print 1 on the standard output when executed?

 public class Q4a39 {     int a = 1;     int b = 1;     int c = 1;     class Inner {         int a = 2;         int get() {             int c = 3;             // Insert statement here.             return c;         }     }     Q4a39() {         Inner i = new Inner();         System.out.println(i.get());     }     public static void main(String[] args) {         new Q4a39();     } } 

Select the two correct answers.

  1. c = b;

  2. c = this.a;

  3. c = this.b;

  4. c = Q4a39.this.a;

  5. c = c;

Q18

Which is the earliest line in the following code after which the object created in the line marked (0) will be a candidate for garbage collection, assuming no compiler optimizations are done?

 public class Q76a9 {     static String f() {         String a = "hello";         String b = "bye";            // (0)         String c = b + "!";          // (1)         String d = b;                // (2)         b = a;                       // (3)         d = a;                       // (4)         return c;                    // (5)     }     public static void main(String[] args) {         String msg = f();         System.out.println(msg);     // (6)     } } 

Select the one correct answer.

  1. The line marked (1).

  2. The line marked (2).

  3. The line marked (3).

  4. The line marked (4).

  5. The line marked (5).

  6. The line marked (6).

Q19

Which method from the String and StringBuffer classes modifies the object on which it is invoked?

Select the one correct answer.

  1. The charAt() method of the String class.

  2. The toUpperCase() method of the String class.

  3. The replace() method of the String class.

  4. The reverse() method of the StringBuffer class.

  5. The length() method of the StringBuffer class.

Q20

Which statement, when inserted at the indicated position in the following code, will cause a runtime exception?

 class A {} class B extends A {} class C extends A {} public class Q3ae4 {     public static void main(String[] args) {         A x = new A();         B y = new B();         C z = new C();         // Insert statement here     } } 

Select the one correct answer.

  1. x = y;

  2. z = x;

  3. y = (B) x;

  4. z = (C) y;

  5. y = (A) y;

Q21

Which of these are keywords in Java?

Select three correct answers.

  1. default

  2. NULL

  3. String

  4. throws

  5. long

Q22

A method within a class is only accessible by classes that are defined within the same package as the class of the method. How can such a restriction be enforced?

Select the one correct answer.

  1. Declare the method with the keyword public .

  2. Declare the method with the keyword protected .

  3. Declare the method with the keyword private .

  4. Declare the method with the keyword package .

  5. Do not declare the method with any accessibility modifiers.

Q23

Which code initializes the two-dimensional array tab so that tab[3][2] is a valid element?

Select the two correct answers.

  1.  int[][] tab = {     { 0, 0, 0 },     { 0, 0, 0 } }; 
  2.  int tab[][] = new int[4][]; for (int i=0; i<tab.length; i++) tab[i] = new int[3]; 
  3.  int tab[][] = {     0, 0, 0, 0,     0, 0, 0, 0,     0, 0, 0, 0,     0, 0, 0, 0 }; 
  4. int tab[3][2];

  5. int[] tab[] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };

Q24

What will be the result of attempting to run the following program?

 public class Qaa75 {     public static void main(String[] args) {         String[][][] arr = {             { {}, null },             { { "1", "2" }, { "1", null, "3" } },             {},             { { "1", null } }         };         System.out.println(arr.length + arr[1][2].length);     } } 

Select the one correct answer.

  1. The program will terminate with an ArrayIndexOutOfBoundsException .

  2. The program will terminate with a NullPointerException .

  3. 4 will be written to standard output.

  4. 6 will be written to standard output.

  5. 7 will be written to standard output.

Q25

Which expressions will evaluate to true if preceded by the following code?

 String a = "hello"; String b = new String(a); String c = a; char[] d = { 'h', 'e', 'l', 'l', 'o' }; 

Select the two correct answers.

  1. (a == "Hello")

  2. (a == b)

  3. (a == c)

  4. a.equals(b)

  5. a.equals(d)

Q26

Which statements are true about the following code?

 class A {     public A() {}     public A(int i) { this(); } } class B extends A {     public boolean B(String msg) { return false; } } class C extends B {     private C() { super(); }     public C(String msg) { this(); }     public C(int i) {} } 

Select the two correct answers.

  1. The code will fail to compile.

  2. The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C .

  3. Class C defines three constructors.

  4. Objects of class B cannot be constructed .

  5. At most one of the constructors of each class is called as a result of constructing an object of class C .

Q27

Given two collection objects referenced by col1 and col2 , which statements are true?

Select the two correct answers.

  1. The operation col1.retainAll(col2) will not modify the col1 object.

  2. The operation col1.removeAll(col2) will not modify the col2 object.

  3. The operation col1.addAll(col2) will return a new collection object, containing elements from both col1 and col2 .

  4. The operation col1.containsAll(Col2) will not modify the col1 object.

Q28

Which statements are true about the relationships between the following classes?

 class Foo {     int num;     Baz comp = new Baz(); } class Bar {     boolean flag; } class Baz extends Foo {     Bar thing = new Bar();     double limit; } 

Select the three correct answers.

  1. A Bar is a Baz .

  2. A Foo has a Bar .

  3. A Baz is a Foo .

  4. A Foo is a Baz .

  5. A Baz has a Bar .

Q29

Which statements are true about the value of a field, when no explicit assignments have been made?

Select the three correct answers.

  1. The value of a field of type int is undetermined.

  2. The value of a field of any numeric type is zero.

  3. The compiler may issue an error if the field is used in a method before it is initialized.

  4. A field of type String will denote the empty string ( "") .

  5. The value of all fields which are references is null .

Q30

Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?

Select the two correct answers.

  1. An object is deleted as soon as there are no more references that denote the object.

  2. The finalize() method will eventually be called on every object.

  3. The finalize() method will never be called more than once on an object.

  4. An object will not be garbage collected as long as it is possible for a live thread to access it through a reference.

  5. The garbage collector will use a mark and sweep algorithm.

Q31

Which main() method will succeed in printing the last program argument to the standard output, and exit gracefully with no output if no program arguments are specified?

Select the one correct answer.

  1.  public static void main(String[] args) {     if (args.length != 0)         System.out.println(args[args.length-1]); } 
  2.  public static void main(String[] args) {     try { System.out.println(args[args.length]); }     catch (ArrayIndexOutOfBoundsException e) {} } 
  3.  public static void main(String[] args) {     int ix = args.length;     String last = args[ix];     if (ix != 0) System.out.println(last); } 
  4.  public static void main(String[] args) {     int ix = args.length-1;     if (ix > 0) System.out.println(args[ix]); } 
  5.  public static void main(String[] args) {     try { System.out.println(args[args.length-1]); }     catch (NullPointerException e) {} } 
Q32

Which statements are true about the collection interfaces?

Select the three correct answers.

  1. Set extends Collection .

  2. All methods defined in Set are also defined in Collection .

  3. List extends Collection .

  4. All methods defined in List are also defined in Collection .

  5. Map extends Collection .

Q33

Which is the legal range of values for a short ?

Select the one correct answer.

  1. “2 7 to 2 7 “1

  2. “2 8 to 2 8

  3. “2 15 to 2 15 “1

  4. “2 16 to 2 16 “1

  5. 0 to 2 16 “1

Q34

What is the name of the method that threads can use to pause their execution until signalled to continue by another thread?

Fill in the name of the method (do not include a parameter list).

Q35

Given the following class definitions, which expression identifies whether the object referred to by obj was created by instantiating class B rather than classes A , C , and D ?

 class A {} class B extends A {} class C extends B {} class D extends A {} 

Select the one correct answer.

  1. obj instanceof B

  2. obj instanceof A && !(obj instanceof C)

  3. obj instanceof B && !(obj instanceof C)

  4. !(obj instanceof C obj instanceof D)

  5. !(obj instanceof A) && !(obj instanceof C) && !(obj instanceof D)

Q36

What will be written to the standard output when the following program is executed?

 public class Q8499 {     public static void main(String[] args) {         double d = -2.9;         int i = (int) d;         i *= (int) Math.ceil(d);         i *= (int) Math.abs(d);         System.out.println(i);     } } 

Select the one correct answer.

  1. -12

  2. 18

  3. 8

  4. 12

  5. 27

Q37

What will be written to the standard output when the following program is executed?

 public class Qcb90 {     int a;     int b;     public void f() {         a = 0;         b = 0;         int[] c = { 0 };         g(b, c);         System.out.println(a + " " + b + " " + c[0] + " ");     }     public void g(int b, int[] c) {         a = 1;         b = 1;         c[0] = 1;     }     public static void main(String[] args) {         Qcb90 obj = new Qcb90();         obj.f();     } } 

Select the one correct answer.

  1. 0 0 0

  2. 0 0 1

  3. 0 1 0

  4. 1 0 0

  5. 1 0 1

Q38

Given the following class, which are correct implementations of the hashCode() method?

 class ValuePair {     public int a, b;     public boolean equals(Object other) {         try {             ValuePair o = (ValuePair) other;             return (a == o.a && b == o.b)                  (a == o.b && b == o.a);         } catch (ClassCastException cce) {             return false;         }     }     public int hashCode() {         // Provide implementation here.     } } 

Select the three correct answers.

  1. return 0;

  2. return a;

  3. return a + b;

  4. return a - b;

  5. return a ^ b;

  6. return (a << 16) b;

Q39

Which statements are true regarding the execution of the following code?

 public class Q3a0a {     public static void main(String[] args) {         int j = 5;         for (int i = 0; i<j; i++) {             assert i < j-- : i > 0;             System.out.println(i*j);         }     } } 

Select the two correct answers.

  1. An AssertionError will be thrown if assertions are enabled at runtime.

  2. The last number printed is 4 if assertions are disabled at runtime.

  3. The last number printed is 20 if assertions are disabled at runtime.

  4. The last number printed is 4 if assertions are enabled at runtime.

  5. The last number printed is 20 if assertions are enabled at runtime.

Q40

Which of the following method names are overloaded?

Select the three correct answers.

  1. The method name yield in java.lang.Thread

  2. The method name sleep in java.lang.Thread

  3. The method name wait in java.lang.Object

  4. The method name notify in java.lang.Object

Q41

Which are valid identifiers?

Select the three correct answers.

  1. _class

  2. $value$

  3. zer@

  4. ngstr m

  5. 2much

Q42

What will be the result of attempting to compile and run the following program?

 public class Q28fd {     public static void main(String[] args) {         int counter = 0;         l1:         for (int i=0; i<10; i++) {             l2:             int j = 0;             while (j++ < 10) {                 if (j > i) break l2;                 if (j == i) {                     counter++;                     continue l1;                 }             }         }         System.out.println(counter);     } } 

Select the one correct answer.

  1. The program will fail to compile.

  2. The program will not terminate normally.

  3. The program will write 10 to the standard output.

  4. The program will write to the standard output.

  5. The program will write 9 to the standard output.

Q43

Given the following interface definition, which definition is valid?

 interface I {     void setValue(int val);     int getValue(); } 

Select the one correct answer.

  1.  class A extends I {     int value;     void setValue(int val) { value = val; }     int getValue() { return value; } } 
  2.  interface B extends I {     void increment(); } 
  3.  abstract class C implements I {     int getValue() { return 0; }     abstract void increment(); } 
  4.  interface D implements I {     void increment(); } 
  5.  class E implements I {     int value;     public void setValue(int val) { value = val; } } 
Q44

Which statements are true about the methods notify() and notifyAll() ?

Select the two correct answers.

  1. An instance of the class Thread has a method named notify that can be invoked.

  2. A call to the method notify() will wake the thread that currently owns the lock of the object.

  3. The method notify() is synchronized.

  4. The method notifyAll() is defined in class Thread .

  5. When there is more than one thread waiting to obtain the lock of an object, there is no way to be sure which thread will be notified by the notify() method.

Q45

Which statements are true about the correlation between the inner and outer instances of member classes?

Select the two correct answers.

  1. Fields of the outer instance are always accessible to inner instances, regardless of their accessibility modifiers.

  2. Fields of the outer instance can never be accessed using only the variable name within the inner instance.

  3. More than one inner instance can be associated with the same outer instance.

  4. All variables from the outer instance that should be accessible in the inner instance must be declared final .

  5. A class that is declared final cannot have any member classes.

Q46

What will be the result of attempting to compile and run the following code?

 public class Q6b0c {     public static void main(String[] args) {         int i = 4;         float f = 4.3;         double d = 1.8;         int c = 0;         if (i == f) c++;         if (((int) (f + d)) == ((int) f + (int) d)) c += 2;         System.out.println(c);     } } 

Select the one correct answer.

  1. The code will fail to compile.

  2. The value will be written to the standard output.

  3. The value 1 will be written to the standard output.

  4. The value 2 will be written to the standard output.

  5. The value 3 will be written to the standard output.

Q47

Which operators will always evaluate all the operands?

Select the two correct answers.

  1. +

  2. &&

  3. ? :

  4. %

Q48

Which statement concerning the switch construct is true?

Select the one correct answer.

  1. All switch statements must have a default label.

  2. There must be exactly one label for each code segment in a switch statement.

  3. The keyword continue can never occur within the body of a switch statement.

  4. No case label may follow a default label within a single switch statement.

  5. A character literal can be used as a value for a case label.

Q49

Which modifiers and return types would be valid in the declaration of a main() method that starts the execution of a Java standalone application?

Select the two correct answers.

  1. private

  2. final

  3. static

  4. int

  5. abstract

  6. String

Q50

Which of the following expressions are valid?

Select the three correct answers.

  1. System.out.hashCode()

  2. "".hashCode()

  3. 42.hashCode()

  4. ("4"+2).equals(42)

  5. (new java.util.Vector()).hashCode()

Q51

Which statement regarding the following method definition is true?

 boolean e() {     try {         assert false;     } catch (AssertionError ae) {         return true;     }     return false;       // (1) } 

Select the one correct answer.

  1. The code will fail to compile since catching an AssertionError is illegal.

  2. The code will fail to compile since the return statement at (1) is unreachable.

  3. The method will return true under all circumstances.

  4. The method will return false under all circumstances.

  5. The method will return true if and only if assertions are enabled at runtime.

Q52

If str denotes a String object with the string "73" , which of these expressions will convert the string to the int value 73?

Select the two correct answers.

  1. Integer.intValue(str)

  2. ((int) str)

  3. (new Integer(str)).intValue()

  4. Integer.parseInt(str)

  5. Integer.getInt(str)

Q53

Insert a line of code at the indicated location that will call the print() method in the Base class.

 class Base {     public void print() {         System.out.println("base");     } } class Extension extends Base {     public void print() {         System.out.println("extension");         // Insert a line of code here.     } } public class Q294d {     public static void main(String[] args) {         Extension ext = new Extension();         ext.print();     } } 

Fill in a single line of code.

Q54

Given the following code, which statements are true?

 public class Vertical {     private int alt;     public synchronized void up() {         ++alt;     }     public void down() {         --alt;     }     public synchronized void jump() {         int a = alt;         up();         down();         assert(a == alt);     } } 

Select the two correct answers.

  1. The code will fail to compile.

  2. Separate threads can execute the up() method concurrently.

  3. Separate threads can execute the down() method concurrently.

  4. Separate threads can execute both the up() and down() method concurrently.

  5. The assertion in the jump() method will not fail under any circumstances.

Q55

What will be written to the standard output when the following program is run?

 public class Q03e4 {     public static void main(String[] args) {         String space = " ";         String composite = space + "hello" + space + space;         composite.concat("world");         String trimmed = composite.trim();         System.out.println(trimmed.length());     } } 

Select the one correct answer.

  1. 5

  2. 6

  3. 7

  4. 12

  5. 13

Q56

Given the following code, which statements are true about the objects referenced through the fields i , j , and k , given that any thread may call the methods a() , b() , and c() at any time?

 class Counter {     int v = 0;     synchronized void inc() { v++; }     synchronized void dec() { v--; } } public class Q7ed5 {     Counter i;     Counter j;     Counter k;     public synchronized void a() {         i.inc();         System.out.println("a");         i.dec();     }     public synchronized void b() {         i.inc(); j.inc(); k.inc();         System.out.println("b");         i.dec(); j.dec(); k.dec();     }     public void c() {         k.inc();         System.out.println("c");         k.dec();     } } 

Select the two correct answers.

  1. i.v is guaranteed always to be 0 or 1.

  2. j.v is guaranteed always to be 0 or 1.

  3. k.v is guaranteed always to be 0 or 1

  4. j.v will always be greater than or equal to k.v at any give time.

  5. k.v will always be greater than or equal to j.v at any give time.

Q57

Which statements are true about casting and conversion?

Select the three correct answers.

  1. Conversion from int to long does not need a cast.

  2. Conversion from byte to short does not need a cast.

  3. Conversion from float to long does not need a cast.

  4. Conversion from short to char does not need a cast.

  5. Conversion from boolean to int using a cast is not possible.

Q58

Which method declarations, when inserted at the indicated position, will not cause the program to fail during compilation?

 public class Qdd1f {     public long sum(long a, long b) { return a + b; }     // Insert new method declarations here. } 

Select the two correct answers.

  1. public int sum(int a, int b) { return a + b; }

  2. public int sum(long a, long b) { return 0; }

  3. abstract int sum();

  4. private long sum(long a, long b) { return a + b; }

  5. public long sum(long a, int b) { return a + b; }

Q59

The 8859-1 character code for the uppercase letter A is the decimal value 65. Which code fragments declare and initialize a variable of type char with this value?

Select the two correct answers.

  1. char ch = 65;

  2. char ch = '\65';

  3. char ch = '\0041';

  4. char ch = 'A';

  5. char ch = "A";

Q60

What will be the result of executing the following program code with assertions enabled?

 import java.util.*; public class Q4d3f {    public static void main(String[] args) {        LinkedList lla = new LinkedList();        LinkedList llb = new LinkedList();        assert lla.size() == llb.size() : "empty";        lla.add("Hello");        assert lla.size() == 1 : "size";        llb.add("Hello");        assert llb.contains("Hello") : "contains";        assert lla.get(0).equals(llb.get(0)) : "element";        assert lla.equals(llb) : "collection";    } } 

Select the one correct answer.

  1. Execution proceeds normally and produces no output.

  2. An AssertionError with the message "size" is thrown.

  3. An AssertionError with the message "empty" is thrown.

  4. An AssertionError with the message "element" is thrown

  5. An IndexOutOfBoundsException is thrown.

  6. An AssertionError with the message "container" is thrown.

Q61

Which of these are keywords in Java?

Select the two correct answers.

  1. Double

  2. native

  3. main

  4. unsafe

  5. default



A Programmer[ap]s Guide to Java Certification
A Programmer[ap]s Guide to Java Certification
ISBN: 201596148
EAN: N/A
Year: 2003
Pages: 284

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net