SCJP - Page -5

41.)
Exhibit:

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

What is the result?

a. The program prints “lava”
b. The program prints “java”
c. An error at line 7 causes compilation to fail.
d. Compilation succeeds but the program throws an exception.
42.)
Given:

5. String foo = “base” ;
6. foo.substring (0,3);
7. foo.concat (“ket”);
8.

Type the value of foo at line 8.

Ans: BASE
43.)
Which two create an instance of an array? (Choose Two)

a. int [] ia = new int [15];
b. float fa = new float [20];
c. char [] ca = “Some String”;
d. Object oa = new float [20];
e. Int ia [] [] = new float [20];
44.)
Exhibit:

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

What is the result?

a. Compilation succeeds and 4 is printed.
b. Compilation succeeds and 43 is printed.
c. An error on line 9 causes compilation to fail.
d. An error on line 14 causes compilation to fail.
e. Compilation succeeds but an exception is thrown at line 9.
45.)
Which four types of objects can thrown using the throw statement? (Choose Four)

a. Error
b. Event
c. Object
d. Exception
e. Throwable
f. RuntimeException
46.)
Given:

1. class BaseClass {
2. Private float x = 1.0f ;
3. protected float getVar () ( return x; )
4. }
5. class Subclass extends BaseClass (
6. private float x = 2.0f;
7. // insert code herre
8. )

Which two are valid examples of method overriding? (Choose Two)

a. Float getVar () { return x; }
b. public float getVar () { return x; }
c. Float double getVar () { return x; }
d. public float getVar () { return x; }
e. public float getVar () { retrun f; }
47.)
Which two valid declarations of a char?(Choose Two)

a. Char ch = “a”;
b. Char ch = '\' ';
c. Char ch = 'cafe';
d. Char ch = “cafe”;
e. Char ch = '\ucafe';
f. Char ch = '\u10100';
g. Char ch = (char) true;
48.)
Given:

1. class super {
2. public float getNum() { return 3.0f ; }
3. )
4.
5. public class Sub extends Super {
6.
7. )

Which method, placed at line 6, will cause a compiler error?

a. Public float getNum () { return 4.0f; }
b. Public void getNum () { }
c. Public void getNum (double d) { }
d. Public double getNum (float d) { return 4.0f; }
49.)
Exhibit:

1. public class X {
2. private static int a;
3.
4. public static void main (String [] args) {
5. modify (a);
6. }
7.
8. public static void modify (int a) {
9. a++;
10. }
11. }

What is the result?

a. The program runs and prints “0”
b. The program runs and prints “1”
c. The program runs but aborts with an exception.
d. En error “possible undefined variable” at line 5 causes compilation to fail.
e. En error “possible undefined variable” at line 10 causes compilation to fail.
50.)
Given:

1. // point X
2. public class foo (
3. public static void main (String [] args) throws Exception {
4. printWriter out = new PrintWriter (new
5. java.io.OutputStreamWriter (System.out) , true;
6. out.println(“Hello”);
7. }
8. }

Which statement at PointX on line 1 allows this code to compile and run?

a. Import java.io.PrintWriter;
b. Include java.io.PrintWriter;
c. Import java.io.OutputStreamWriter;
d. Include java.io.OutputStreamWriter;
e. No statement is needed.