
Oracle Java SE 8 Programmer I - 1z0-808 Exam Questions
QUESTION NO: 1
Given the code fragment:

What is the result?
Given the code fragment:

What is the result?
Correct Answer: D
QUESTION NO: 2
Given:
class Cake {
int model;
String flavor;
Cake() {
model = 0;
flavor = "Unknown";
}
}
public class Test {
public static void main(String[] args) {
Cake c = new Cake();
bake1(c);
System.out.println(c.model + " " + c.flavor);
bake2(c);
System.out.println(c.model + " " + c.flavor);
}
public static Cake bake1(Cake c) {
c.flavor = "Strawberry";
c.model = 1200;
return c;
}
public static void bake2(Cake c) {
c.flavor = "Chocolate";
c.model = 1230;
return;
}
}
What is the result?
Given:
class Cake {
int model;
String flavor;
Cake() {
model = 0;
flavor = "Unknown";
}
}
public class Test {
public static void main(String[] args) {
Cake c = new Cake();
bake1(c);
System.out.println(c.model + " " + c.flavor);
bake2(c);
System.out.println(c.model + " " + c.flavor);
}
public static Cake bake1(Cake c) {
c.flavor = "Strawberry";
c.model = 1200;
return c;
}
public static void bake2(Cake c) {
c.flavor = "Chocolate";
c.model = 1230;
return;
}
}
What is the result?
Correct Answer: D
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 3
Given the code fragment:

What is the result?
Given the code fragment:

What is the result?
Correct Answer: B
QUESTION NO: 4
Which three statements are true about the structure of a Java class? (Choose three.)
Which three statements are true about the structure of a Java class? (Choose three.)
Correct Answer: B,C,E
QUESTION NO: 5
Given the code fragment:

Test.java:

Which is the result?
Given the code fragment:

Test.java:

Which is the result?
Correct Answer: B
QUESTION NO: 6
Consider following interface.

Which of the following will create instance of Runnable type?
Consider following interface.

Which of the following will create instance of Runnable type?
Correct Answer: E
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 7
Which of the following can fill in the blank in this code to make it compile?

Which of the following can fill in the blank in this code to make it compile?

Correct Answer: A
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 8
Given the code fragment:

What is the result?
Given the code fragment:

What is the result?
Correct Answer: B
QUESTION NO: 9
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?
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: B
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 10
Given the code fragment:

Given the code fragment:

Correct Answer: D
QUESTION NO: 11
Given:
class Base {
// insert code here
}
public class Derived extends Base{
public static void main(String[] args) {
Derived obj = new Derived();
obj.setNum(3);
System.out.println("Square = " + obj.getNum() * obj.getNum());
}
}
Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?
Given:
class Base {
// insert code here
}
public class Derived extends Base{
public static void main(String[] args) {
Derived obj = new Derived();
obj.setNum(3);
System.out.println("Square = " + obj.getNum() * obj.getNum());
}
}
Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?
Correct Answer: A,C
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 12
Given the code fragment:

What is the result?
Given the code fragment:

What is the result?
Correct Answer: B
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).
QUESTION NO: 13
Given:
public class CheckIt {
public static void main (String[] args) {
if (doCheck()) {
System.out.print("square ");
}
System.out.print("...");
}
public static int doCheck() {
return 0;
}
}
Given:
public class CheckIt {
public static void main (String[] args) {
if (doCheck()) {
System.out.print("square ");
}
System.out.print("...");
}
public static int doCheck() {
return 0;
}
}
Correct Answer: B
QUESTION NO: 14
Given the fragment:

What is the result?
Given the fragment:

What is the result?
Correct Answer: D
QUESTION NO: 15
Given:
public class ComputeSum {
public int x;
public int y;
public int sum;
public ComputeSum (int nx, int ny) {
x = nx; y =ny;
updateSum();
}
public void setX(int nx) { x = nx; updateSum();}
public void setY(int ny) { x = ny; updateSum();}
void updateSum() { sum = x + y;}
}
This class needs to protect an invariant on the sum field.
Which three members must have the private access modifier to ensure that this invariant is maintained?
Given:
public class ComputeSum {
public int x;
public int y;
public int sum;
public ComputeSum (int nx, int ny) {
x = nx; y =ny;
updateSum();
}
public void setX(int nx) { x = nx; updateSum();}
public void setY(int ny) { x = ny; updateSum();}
void updateSum() { sum = x + y;}
}
This class needs to protect an invariant on the sum field.
Which three members must have the private access modifier to ensure that this invariant is maintained?
Correct Answer: C,E,F
Explanation: Only visible for Pass4Test members. You can sign-up / login (it's free).




