Free Oracle 1Z0-808 practice questions

10 free Oracle 1Z0-808 practice questions with the correct answer and a full explanation for each, taken from the CertStash pack of 234 questions. Work through them, then open each answer to check your reasoning.

Question 1

Given:

What is the result?

Exhibit for question 1

  1. 200.0 : 100.0
  2. 400.0 : 200.0
  3. 400.0 : 100.0
  4. Compilation fails.
Show answer and explanation

Correct answer: C. 400.0 : 100.0

The code creates a Product object with price 200. The updatePrice method receives the product object by reference and the newPrice value 100. Inside updatePrice, price is first set to 100 * 2 = 200, then product.price is incremented by this local price variable: product.price = 200 + 200 = 400. The method prints prt.price (400.0) concatenated with newPrice (100.0), producing '400.0 : 100.0'. Since objects are passed by reference in Java, the modifications to the product object persist after the method call.

Why the other options are wrong

  • A. This ignores that price is doubled inside updatePrice to 200 before being added to product.price.
  • B. This would result from incorrectly assuming newPrice is also doubled or added twice to the product price.
  • D. The code is syntactically valid Java with no compilation errors.

Question 2

Which statement is true about the switch statement?

  1. It must contain the default section.
  2. The break statement, at the end of each case block, is optional.
  3. Its case label literals can be changed at runtime.
  4. Its expression must evaluate to a collection of values.
Show answer and explanation

Correct answer: B. The break statement, at the end of each case block, is optional.

The break statement at the end of each case block is optional in Java switch statements. When omitted, execution falls through to the next case (fall-through behavior). The default section is not required, a switch can function without it. Case label literals must be compile-time constants and cannot change at runtime. The switch expression must evaluate to a single value (or collection in enhanced switch), not multiple values.

Why the other options are wrong

  • A. The default section is optional; a switch statement can be valid without it.
  • C. Case label literals are compile-time constants and cannot be modified at runtime.
  • D. The switch expression evaluates to a single value, not a collection of values.

Question 3

Given the code fragment:

What is the result?

Exhibit for question 3

  1. May 04, 2014T00:00:00.000
  2. 2014-05-04T00:00: 00.000
  3. 5/4/14T00:00:00.000
  4. An exception is thrown at runtime.
Show answer and explanation

Correct answer: D. An exception is thrown at runtime.

The code attempts to chain methods on the result of LocalDate.parse(), but LocalDate.parse() returns a LocalDate object, which does not have a .format() method that accepts a DateTimeFormatter parameter in this way. LocalDate lacks time components, so formatting with DateTimeFormatter.ISO_DATE_TIME (which includes time) would require conversion to a LocalDateTime or ZonedDateTime first. Additionally, the chaining syntax shown attempts to call .format() directly on the parse result without proper method availability, causing a compilation or runtime error. The code as written cannot execute successfully.

Why the other options are wrong

  • A. This output format does not match ISO_DATE_TIME pattern and the code would not compile/run to produce any output.
  • B. While this looks like a plausible ISO format output, the code throws an exception because LocalDate does not support formatting with ISO_DATE_TIME formatter directly.
  • C. This is not the ISO_DATE_TIME format pattern, and the code fails before any output could be generated.

Question 4

Given the code fragment:

What is the result?

Exhibit for question 4

  1. Sum is 600
  2. Compilation fails at line n1.
  3. Compilation fails at line n2.
  4. A ClassCastException is thrown at line n1.
  5. A ClassCastException is thrown at line n2.
Show answer and explanation

Correct answer: C. Compilation fails at line n2.

At line n2, the code attempts to cast a Long object (s3) to a String: `String s4 = (String) (s3 * s2);`. The expression `s3 * s2` performs arithmetic multiplication between a Long and an Integer, resulting in a Long primitive value. This Long value is then boxed into a Long object. Attempting to cast a Long object to a String type is invalid and will cause a compilation error because Long and String are incompatible types with no valid casting relationship. The compiler rejects this cast before runtime.

Why the other options are wrong

  • A. The code does not compile successfully, so no output is produced.
  • B. Line n1 compiles without error; it casts a long primitive to Long, which is valid widening and boxing.
  • D. ClassCastException is a runtime exception that occurs when invalid casts pass compilation; this cast fails at compile time instead.
  • E. ClassCastException is a runtime exception; the compilation error at line n2 prevents the code from running.

Question 5

What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?

  1. Encapsulation
  2. Inheritance
  3. Abstraction
  4. Instantiation
  5. Polymorphism
Show answer and explanation

Correct answer: A. Encapsulation

Encapsulation is the Java concept that uses access modifiers (private, protected, public, default) to protect variables and hide them within a class, controlling access through public methods. This protects internal state and enforces controlled interaction with object data.

Why the other options are wrong

  • B. Inheritance is the mechanism for a class to extend another class and reuse its behavior.
  • C. Abstraction is the concept of hiding implementation complexity while exposing only essential features.
  • D. Instantiation is the process of creating an object from a class.
  • E. Polymorphism is the ability of objects to take multiple forms or for methods to behave differently based on context.

Question 6

Given the code fragment:

Which two modifications, made independently, enable the code to compile? (Choose two.)

Exhibit for question 6

  1. Make the method at line n1 public.
  2. Make the method at line n2 public.
  3. Make the method at line n3 public.
  4. Make the method at line n3 protected.
  5. Make the method at line n4 public.
Show answer and explanation

Correct answer: C, D

C. Make the method at line n3 public. D. Make the method at line n3 protected. The Earth class extends Planet and must implement the abstract method rotate() declared at line n2. Currently, Earth's rotate() method at line n4 is protected, which violates the contract that an overridden abstract method cannot have a more restrictive access modifier. Making line n4 public allows Earth to properly implement the abstract method. Additionally, Earth overrides the concrete method revolve() at line n3 with a public override, which is valid since public is less restrictive than protected. Making line n3 public satisfies the Liskov Substitution Principle by ensuring the subclass method is at least as accessible as the parent's protected method, enabling proper polymorphic behavior.

Why the other options are wrong

  • A. Making the protected revolve() method at line n1 public does not resolve the abstract rotate() implementation issue that prevents compilation.
  • B. Making the abstract rotate() method at line n2 public does not help; the problem is that Earth fails to properly implement it with appropriate access modifiers.
  • E. Making line n4 public alone would fix the abstract method implementation, but line n3's override of revolve() should also be made public for consistency; this is not sufficient as a standalone modification.

Question 7

Given:

And given the code fragment:

What is the result?

Exhibit for question 7

  1. 4W 100 Auto 4W 150 Manual
  2. null 0 Auto 4W 150 Manual
  3. Compilation fails only at line n1
  4. Compilation fails only at line n2
  5. Compilation fails at both line n1 and line n2
Show answer and explanation

Correct answer: A. 4W 100 Auto 4W 150 Manual

Line n1 calls Car(String trans) which does not call super(), so it uses the default Vehicle constructor setting type="4W" and maxSpeed=100. Line n2 calls Car(String type, int maxSpeed, String trans) which properly calls super(type, maxSpeed), so it sets type="4W" and maxSpeed=150. Both constructors compile successfully. c1 is created with Car("Auto"), resulting in type="4W", maxSpeed=100, trans="Auto". c2 is created with Car("4W", 150, "Manual"), resulting in type="4W", maxSpeed=150, trans="Manual". The output prints both objects' properties correctly: "4W 100 Auto" and "4W 150 Manual".

Why the other options are wrong

  • B. c1.type is not null; it is set to "4W" by the default Vehicle constructor implicitly called in the first Car constructor.
  • C. Line n1 compiles without error; the Car(String trans) constructor is valid and implicitly calls the default Vehicle constructor.
  • D. Line n2 compiles without error; it properly invokes super(type, maxSpeed) to initialize the parent class.
  • E. Both lines compile successfully; there are no compilation failures at either line n1 or n2.

Question 8

Given:

What is the result?

Exhibit for question 8

  1. Compilation fails at line n1.
  2. Initialized Started Initialized
  3. Initialized Started
  4. Compilation fails at line n2.
Show answer and explanation

Correct answer: A. Compilation fails at line n1.

The code attempts to call c.init() at line n2, but init() is declared as private in the Caller class. Private methods cannot be accessed from outside their class, even from instances of that class when accessed through external code. Since TestCall is a different class attempting to call the private init() method on a Caller object, the compilation will fail at line n2 with an access modifier error. The call to c.start() at line n1 succeeds because start() is declared as private but is being called from within the TestCall class on an instance; however, the real issue is that line n2 violates Java's access control rules, preventing the code from compiling at all.

Why the other options are wrong

  • B. This output assumes both lines execute successfully, but line n2 fails compilation because init() is private and cannot be called from the TestCall class.
  • C. This output represents what would happen if only line n1 executed, but the code never runs because compilation fails at line n2.
  • D. Compilation fails at line n2, not line n1, since start() is accessible as a private method being called through the object reference, whereas init() is private and inaccessible from outside the Caller class.

Question 9

Given these two classes:

Any amount of electricity used by a customer (represented by an instance of the Customer class) must contribute to the customer's bill (represented by the member variable bill) through the useElectricity method.

An instance of the Customer class should never be able to tamper with or decrease the value of the member variable bill.

How should you write methods in the ElectricAccount class at line n1 so that the member variable bill is always equal to the value of the member variable kwh multiplied by the member variable rate?

Exhibit for question 9

Exhibit for question 9

Show answer and explanation

Correct answer: B. public void addKWh(double kWh) {

The Customer class must never be able to tamper with or decrease the bill value, and bill must always equal kWh multiplied by rate. Option B is correct because it uses a public method with validation to ensure only positive kWh values are accepted and added. The bill is then recalculated directly within the method, preventing external manipulation. While option A accomplishes the calculation, it lacks input validation to prevent negative values from decreasing the bill. Option C uses a private method, making it inaccessible to the Customer class, which defeats the purpose of the useElectricity method that calls addKWh. Option D exposes a separate public setBill method, allowing the Customer class to directly manipulate the bill value, violating the requirement that the customer cannot tamper with the bill.

Why the other options are wrong

  • A. Lacks validation to prevent negative kWh values from decreasing the bill.
  • C. Uses private access modifier, making the method inaccessible to the Customer class.
  • D. Exposes a public setBill method that allows direct manipulation of the bill variable.

Question 10

Given the code fragment:

What is the result?

Exhibit for question 10

  1. Match 1
  2. Match 2
  3. No Match
  4. A NullPointerException is thrown at runtime.
Show answer and explanation

Correct answer: A. Match 1

The code creates a StringBuilder with "Java" and a String with "Java". The first condition checks if sb.toString().equals(s.toString()), which compares "Java" to "Java" using the equals() method. Since both represent the same string value, this condition is true and "Match 1" is printed. The program never reaches the subsequent else-if or else blocks.

Why the other options are wrong

  • B. The second condition (sb.equals(s)) is never evaluated because the first condition is already true and the if-else chain terminates.
  • C. The first comparison succeeds because toString() on the StringBuilder produces "Java", which equals the String "Java".
  • D. No NullPointerException occurs; the StringBuilder is properly initialized and toString() is safely called on non-null objects.

That was 10 of 234.

The full Oracle 1Z0-808 pack has all 234 questions, each with the answer, the explanation and why the other options are wrong, plus a questions-only copy for timed runs. US$39, paid once, with free monthly updates and a pass-or-your-money-back guarantee.

Get the full pack