Oracle Java SE 7 Programmer I - 1Z1-803 Exam Practice Test

Given: What is the result?
Correct Answer: B
Given the code fragment:
List colors = new ArrayList();
colors.add("green");
colors.add("red");
colors.add("blue");
colors.add("yellow");
colors.remove(2);
colors.add(3,"cyan");
System.out.print(colors);
What is the result?
Correct Answer: C
Explanation: (Only visible to ExamsLabs members)
Given:

What is the result?
Correct Answer: A
Explanation: (Only visible to ExamsLabs members)
Given the code fragment:
Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}};
Systemout.printIn(array [4] [1]);
System.out.printIn (array) [1] [4]);
What is the result?
Correct Answer: D
Explanation: (Only visible to ExamsLabs members)
Given:

Which approach ensures that the class can be compiled and run?
Correct Answer: D
Explanation: (Only visible to ExamsLabs members)
Which three statements are true about the structure of a Java class?
Correct Answer: A,B,D
Explanation: (Only visible to ExamsLabs members)
Which statement is true about the default constructor of a top-level class?
Correct Answer: D
Explanation: (Only visible to ExamsLabs members)
Given the code fragment:

What is the result?
Correct Answer: D
View the exhibit: What is the result when this program is executed?

Correct Answer: C
Explanation: (Only visible to ExamsLabs members)
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
Correct Answer: A,B
public class Two {
public static void main(String[] args) {
try {
doStuff();
system.out.println("1");
}
catch {
system.out.println("2");
}}
public static void do Stuff() {
if (Math.random() > 0.5) throw new RunTimeException(); doMoreStuff();
System.out.println("3 ");
}
public static void doMoreStuff() {
System.out.println("4");
}
}
Which two are possible outputs?
Correct Answer: B,D
Explanation: (Only visible to ExamsLabs members)
Given:

What is the reference type of myZ and what is the type of the object it references?
Correct Answer: B
Given:
Correct Answer: C
Given:
abstract class A1 { public abstract void m1(); public void m2() { System.out.println("Green"); }
}
abstract class A2 extends A1 { public abstract void m3(); public void m1() { System.out.println("Cyan"); } public void m2() { System.out.println("Blue"); }
}
public class A3 extends A2 { public void m1() { System.out.println("Yellow"); }
public void m2() { System.out.println("Pink"); }
public void m3() { System.out.println("Red"); }
public static void main(String[] args) {
A2 tp = new A3();
tp.m1();
tp.m2();
tp.m3();
}
}
What is the result?
Correct Answer: B
Explanation: (Only visible to ExamsLabs members)
Given:
class Base {
public static void main(String[] args) {
System.out.println("Base " + args[2]);
}
}
public class Sub extends Base{
public static void main(String[] args) {
System.out.println("Overriden " + args[1]);
}
}
And the commands:
javac Sub.java
java Sub 10 20 30
What is the result?
Correct Answer: D
Given the code fragment:
1.ArrayList<Integer> list = new ArrayList<>(1);
2.list.add(1001);
3.list.add(1002);
4.System.out.println(list.get(list.size()));
What is the result?
Correct Answer: B
Explanation: (Only visible to ExamsLabs members)
Given:
public class Natural { private int i; void disp() { while (i <= 5) { for (int i=1; i <=5;) { System.out.print(i + " ");
i++; } i++; } } public static void main(String[] args) { new Natural().disp(); }
} What is the result?
Correct Answer: B
Explanation: (Only visible to ExamsLabs members)
Give:

What value should replace kk in line x to cause jj = 5 to be output?
Correct Answer: E
Explanation: (Only visible to ExamsLabs members)