SCJP - Page -11

101.)
Which interface does java.util.Hashtable implement?

a. java.util.Map
b. java.util.List
c. java.util.Hashable
d. java.util.Collection
102.)
Given:

1. abstract class AbstractIt {
2. abstract float getFloat();
3. }
4. public class AbstractTest extends AbstractIt {
5. private float f1 = 1.0f;
6. private float getFloat() { return f1; }
7. }

What is the result?

a. Compilation succeeds.
b. An exception is thrown.
c. Compilation fails because of an error at line 2.
d. Compilation fails because of an error at line 6.
103.)
Given:
1. public class Test {
2. private static int[] x;
3. public static void main (String[] args) {
4. System.out.println(x[0]);
5. }
6. }

What is the result?

a. 0
b. null
c. Compilation fails.
d. A NullPointerException is thrown at runtime.
e. An ArrayIndexOutOfBoundsException is thrown at runtime.
104.)
Which two provide the capability to store objects using a key-value pair? (Choose two.)

a. java.util.Map
b. java.util.Set
c. java.util.List
d. java.util.SortedSet
e. java.util.SortedMap
f. java.util.Collection
105.)
Given:

1. public class Test {
2. public static void replaceJ(String text) {
3. text.replace(“j”, “l”);
4. }
5. public static void main(String args[]) {
6. String text = new String (“java”);
7. replaceJ(text);
8. System.out.println(text);
9. }
10. }

What is the result?

a. lava
b. java
c. Compilation fails.
d. An exception is thrown at runtime
106.)
Which two are valid method signatures in an interface declaration? (Choose two).

a. void method1();
b. public void method2();
c. protected void method3();
d. final public void method4();
e. static public void method5();
107.)
Click the Exhibit button.

What is the result when main is executed?

1. class A {
2. public A() {
3. System.out.println(“hello from a”);
4. }
5. }
6. class B extends A {
7. public B() {
8. System.out.println(“hello from b”);
9. super();
10. }
11. }
12. public class Test {
13. public static void main(String args[]) {
14. A a = new B();
15. }
16. }

a. Compilation fails.
b. hello from a
c. hello from b
d. hello from b
hello from a
e. hello from a
hello from b
108.)
Click the Exhibit button.

What is the output?

1. class Super {
2. public Integer getLength() { return new Integer (4); }
3. }
4.
5. public class Sub extends Super {
6. public Long getLength () { return new Long (5); }
7.
8. public static void main (String[] args); {
9. Super sooper = new Super ();
10. Sub sub = new Sub ();
11. System.out.println (
12. sooper.getLength().toString() + “,” +
13. sub.getLength() .toString() );
14. }
15. }

a. 4,4
b. 4,5
c. 5,4
d. 5,5
e. Compilation fails
109.)
Given.

1. class EnclosingOne {
2. public class InsideOne { }
3. }
4. public class InnerTest {
5. public static void main(String[] args) {
6. EnclosingOne eo = new EnclosingOne();
7. // insert code here
8. }
9. }

Which statement at line 7 constructs an instance of the inner class?

a. InsideOne ei = eo.new InsideOne();
b. eo.InsideOne ei = eo.new InsideOne();
c. InsideOne ei = EnclosingOne.new InsideOne();
d. EnclosingOne.InsideOne ei = eo.new InsideOne();
110.)
Given:

1. interface I0 {
2. public int method1(int x, int y);
3. public long method1(long x, long y);
4. }

which compiles?

a. interface I1 extends I0 { }
b. interface I1 implements I0 { }
c. abstract class C1 extends I0 {
public int method1(int x, int y) { return 0; }
}
d. abstract class C1 implements I0 {
public int method1(int x, int y) { return 0; }
}
e. class C1 implements I0 {
public int method1(int x, int y) { return 0; }
public shot method1(long x, long y) { return 0; }
}
Prev 1 2 3 4 5 6 7 8 9