SCJP - Page -4

31.)
Given:

1. public class Foo {
2. public static void main (String []args) {
3. int i = 1;
4. int j = i++;
5. if ((i>++j) && (i++ ==j)) {
6. i += j;
7. }
8. }
9. }

What is the final value of i?

a. 1
b. 2
c. 3
d. 4
e. 5
32.)
Which is a valid identifier?

a. false
b. default
c. _object
d. a-class
33.)
Given:

1. String foo = “blue”;
2. Boolean []bar = new Boolean [1];
3. if (bar[0]) {
4. foo = “green”;
5. }

What is the result?

a. Foo has the value of “”
b. Foo has the value of null.
c. Foo has the value of “blue”
d. Foo has the value of “green”
e. An exception is thrown.
f. The code will not compile.
34.)
Exhibit:

1. public class X {
2. public static void main (String []args) {
3. string s = new string (“Hello”);
4. modify (s);
5. System.out.println(s);
6. }
7.
8. public static void modify (String s) {
9. s += “world!”;
10. }
11. }

What is the result?

a. The program runs and prints “Hello”
b. An error causes compilation to fail.
c. The program runs and prints “Hello world!”
d. The program runs but aborts with an exception.
35.)
Exhibit:

1. public class enclosingone (
2. public class insideone{}
3.)
4. public class inertest (
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?
Leading the way in IT testing and certification tools, www.testking.com
-9

a. InsideOnew ei = eo.new InsideOn();
b. Eo.InsideOne ei = eo.new InsideOne();
c. InsideOne ei = EnclosingOne.new InsideOne();
d. EnclosingOne.InsideOne ei = eo.new InsideOne();
36.)
Exhibit:

1. public class test (
2. public int aMethod() [
3. static int i=0;
4. i++;
5. return I;
6. }
7. public static void main (String args[]) {
8. test test = new test();
9. test.aMethod();
10. int j = test.aMethod();
11. System.out.println(j);
12. ]
13. }

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”
37.)
Which method in the Thread class is used to create and launch a new thread of execution?

a. Run();
b. Start();
c. Execute();
d. Run (Runnable r);
e. Start (Runnable r);
f. Execute (Thread t);
38.)
Which declaration prevents creating a subclass of an outer class?

a. Static class FooBar{}
b. Private class FooBar{}
c. Abstract public class FooBar{}
d. Final public class FooBar{}
e. Final abstract class FooBar{}
39.)
Given:

1. public class IfTest (
2. public static void main(string []args) {
3. int x = 3;
4. int y = 1;
5. if (x = y)
6. System.out.println(“ Not equal”);
7. else
8. System.out.println(“Equal”);
9. }
10. }

What is the result?

a. The output is “Equal”
b. The output in “Not equal”
c. An error at line 5 causes compilation to fail.
d. The program executes but does not print a message.
40.)
Given:

1. public class X {
2. public static void main (String []args) {
3. byte b = 127;
4. byte c = 126;
5. byte d = b + c;
6. }
7. }

Which statement is true?

a. Compilation succeeds and d takes the value 253.
b. Line 5 contains an error that prevents compilation.
c. Line 5 throws an exceprion indicating “Out of range”
d. Line 3 and 4 contain error that prevent compilation.
e. The compilation succeeds and d takes the value of 1.