SCJP - Page -2



11.)
Given:
1. public class Test {
2. public static void main (String [] args) {
3. string foo = “blue”;
4. string bar = foo;
5. foo = “green”;
6. System.out.println(bar);
7. }
8. }

What is the result?

a. An exception is thrown.
b. The code will not compile.
c. The program print “null”
d. The program prints “blue”
e. The program prints “green”
12.)
Exhibit:

1. class super(
2. public int I = 0;
3. public super (string text) (
4. I = 1
5. )
6. )
7. public class sub extends super (
8. public sub (string text) (
9. i = 2
10. )
11. public static void main (string args[]) (
12. sub sub = new sub (“Hello”);
13. system.out.println(sub.i);
14. )
15. )

What is the result?

a. Compilation will fail.
b. Compilation will succeed and the program will print “0”
c. Compilation will succeed and the program will print “1”
d. Compilation will succeed and the program will print “2”
13.)
Which code determines the int value foo closest to, but not greater than, a double value bar?

a. Int foo = (int) Math.max (bar);
b. Int foo = (int) Math.min (bar);
c. Int foo = (int) Math.abs (bar);
d. Int foo = (int) Math.ceil (bar);
e. Int foo = (int) Math.floor (bar);
f. Int foo = (int) Math.round(bar);
14.)
What is the numerical range of a char?

a. 0...32767
b. 0...65535
c. -256...255
d. -32768...32767
e. Range is platform dependent.
15.)
Given:

3. int i = 1, j = 10;
4. do (
5. if (i++> --j) continue;
6. ) while (i<5);

After execution, what are the value for I and J?

a. i = 6 and j = 5
b. i = 5 and j = 5
c. i = 6 and j = 4
d. i = 5 and j = 6
e. i = 6 and j = 6
16.)
Given:

1. public class Test {
2. public static void main (String [] args) {
3. unsigned byte b = 0;
4. b--;
5.
6. }
7. }

What is the value of b at line 5?

a. -1
b. 255
c. 127
d. Compilation will fail.
e. Compilation will succeed but the program will throw an exception at line 4.
17.)
Which statement is true?

a. An anonymous inner class may be declared as final.
b. An anonymous inner class can be declared as private.
c. An anonymous inner class can implement multiple interfaces.
d. An anonymous inner class can access final variables in any enclosing scope.
e. Construction of an instance of a static inner class requires an instance of the enclosing
outer class.
18.)
Given the ActionEvent, which method allows you to identify the affected component?

a. GetClass .
b. GetTarget .
c. GetSource .
d. GetComponent .
e. GetTargetComponent .
19.)
Which gets the name of the parent directory file “file.txt” ?

a. String name = File.getParentName (“file.txt”);
b. String name = (name File (“file.txt”)).getParent();
c. String name = (new File (“file.txt”)).getParentName();
d. String name = (new File (“file.txt”)).getParentFile();
e. String name = (new File (“file.txt”)).getParentDir();
String name = dir.getName();
20.)
Which two statements are true regarding the creation of a default constructor? (Choose Two)

a. The default constructor initializes method variables.
b. The default constructor invokes the no-parameter constructor of the superclass.
c. The default constructor initializes the instance variables declared in the class.
d. If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates
a default constructor.
e. The compiler creates a default constructor only when there are no other constructors
for the class.