Q1. public class StringReplace {
public static void main(String[] args) {
String message = "Hi everyone!";
System.out.println("message = " + message.replace("e", "X")); }
}
What is the result?
A. message = Hi everyone!
B. message = Hi XvXryonX!
C. A compile time error is produced.
D. A runtime error is produced.
E. message =
F. message = Hi Xveryone!
Answer: B
Q2. Why will the code not compile?
A. A static field cannot be private.
B. The getLetter method has no body.
C. There is no setLetter method.
D. The letter field is uninitialized.
E. It contains a method named Main instead of ma
Answer: B
Q3. racle 1z0-803 : Practice Test
j = (3 * ((2+4) + 5));
System.out.println("i:"+ i + "\nj":+j);
What is the result?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Q4. Given:
Which two are possible outputs?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: AD
Q5. Which two will compile, and can be run successfully using the command:
Java fred1 hello walls
A. Option A
B. Option B
C. Option C
D. Option D
Answer: CD
Q6. Which code fragment is illegal?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Q7. Given the code fragment:
What could expression1 and expression2 be, respectively, in order to produce output –8, 16?
A. + +a, - -b
B. + +a, b-
C. A+ +, - - b
D. A + +, b -
Answer: D
Q8. Given the code fragment:
int [][] array2d = new int[2][3];
System.out.println("Loading the data.");
for ( int x = 0; x < array2d.length; x++) {
for ( int y = 0; y < array2d[0].length; y++) {
System.out.println(" x = " + x);
System.out.println(" y = " + y);
// insert load statement here.
}
}
System.out.println("Modify the data. ");
for ( int x = 0; x < array2d.length; x++) {
for ( int y = 0; y < array2d[0].length; y++) {
System.out.println(" x = " + x);
System.out.println(" y = " + y);
// insert modify statement here.
}
}
Which pair of load and modify statement should be inserted in the code? The load
statement should set the array's x row and y column value to the sum of x and y
The modify statement should modify the array's x row and y column value by multiplying it by 2
A. Load statement: array2d(x,y) = x + y;
Modify statement: array2d(x,y) = array2d(x,y) * 2
B. Load statement: array2d[x y] = x + y;
Modify statement: array2d[x y] = array2d[x y] * 2
C. Load statement: array2d[x,y] = x + y;
Modify statement: array2d[x,y] = array2d[x,y] * 2
Oracle 1z0-803 : Practice Test
D. Load statement: array2d[x][y] = x + y;
Modify statement: array2d[x][y] = array2d[x][y] * 2
E. Load statement: array2d[[x][y]] = x + y;
Modify statement: array2d[[x][y]] = array2d[[x][y]] * 2
Answer: D
Q9. Given:
Class A { }
Class B { }
Interface X { }
Interface Y { }
Which two definitions of class C are valid?
A. Class C extends A implements X { }
B. Class C implements Y extends B { }
C. Class C extends A, B { }
D. Class C implements X, Y extends B { }
E. Class C extends B implements X, Y { }
Answer: AE
Q10. Given the code fragment:
String name = "Spot";
int age = 4;
String str ="My dog " + name + " is " + age;
System.out.println(str);
And
StringBuilder sb = new StringBuilder();
Using StringBuilder, which code fragment is the best potion to build and print the following
string My dog Spot is 4
A. sb.append("My dog " + name + " is " + age); System.out.println(sb);
B. sb.insert("My dog ").append( name + " is " + age); System.out.println(sb);
C. sb.insert("My dog ").insert( name ).insert(" is " ).insert(age); System.out.println(sb);
D. sb.append("My dog ").append( name ).append(" is " ).append(age);
System.out.println(sb);
Answer: AD