2 packs: 15% off with code BUY2. 3 or more: 20% off with code BUY3.

Free Oracle 1Z0-808 Practice Questions

17 free Oracle 1Z0-808 practice questions from the CertStash pack of 234, each with the correct answer and a full explanation. The rule is the same for every exam: ten free on the product page, 17 free here, all 234 in the pack, and each step includes the one before it.

Question 1

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. When omitted, execution continues to the next case (fall-through behavior). The default section is also optional, not required. Case label literals are compile-time constants and cannot be changed at runtime. The switch expression must evaluate to a single value, not a collection.

Why the other options are wrong

  • A. The default section is optional in switch statements.
  • C. Case label literals are constants determined at compile time and cannot be modified at runtime.
  • D. The switch expression evaluates to a single value, not a collection of values.

Question 2

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 (public, private, protected) to protect variables and methods, hiding them within a class and controlling what is exposed to the outside world. Inheritance involves extending classes, abstraction hides complexity, instantiation creates objects, and polymorphism allows methods to have multiple forms.

Why the other options are wrong

  • B. Inheritance is about extending classes and reusing functionality from parent classes.
  • C. Abstraction is about hiding implementation details and showing 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 methods to have different implementations.

Question 3

Which statement best describes encapsulation?

  1. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.
  2. Encapsulation ensures that classes can be designed so that their methods are inheritable.
  3. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract.
  4. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method.
Show answer and explanation

Correct answer: A. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.

Encapsulation ensures that classes can be designed with controlled access to fields and methods through access modifiers, allowing only certain members to be accessible from outside the class. This is the core purpose of encapsulation. Inheritability of methods is a feature of inheritance, not encapsulation. Abstract declarations relate to abstraction. Polymorphic parameter handling is a feature of polymorphism and inheritance.

Why the other options are wrong

  • B. Method inheritance is a feature of inheritance, not encapsulation.
  • C. Abstract field and method declarations relate to abstraction, not encapsulation.
  • D. Polymorphic parameter substitution is a feature of inheritance and polymorphism, not encapsulation.

Question 4

Which three are advantages of the Java exception mechanism? (Choose three.)

  1. Improves the program structure because the error handling code is separated from the normal program function
  2. Provides a set of standard exceptions that covers all possible errors
  3. Improves the program structure because the programmer can choose where to handle exceptions
  4. Improves the program structure because exceptions must be handled in the method in which they occurred
  5. Allows the creation of new exceptions that are customized to the particular program being created
Show answer and explanation

Correct answer: A, C, E. Improves the program structure because the error handling code is separated from the normal program function; Improves the program structure because the programmer can choose where to handle exceptions; Allows the creation of new exceptions that are customized to the particular program being created

The three advantages of Java's exception mechanism are: A) it separates error handling code from normal program logic, improving structure; C) it allows programmers to choose at which level in the call stack to handle exceptions, rather than handling them locally; and E) it enables creation of custom exceptions tailored to specific application needs. Option B is incorrect because no set of standard exceptions can cover all possible errors. Option D is incorrect because exceptions do not need to be handled in the method where they occur, they can be thrown up the call stack.

Why the other options are wrong

  • B. Standard exceptions cannot comprehensively cover all possible errors that might occur in programs.
  • D. Exceptions can be thrown up the call stack and handled in calling methods, not necessarily where they occur.

Question 5

Which three statements describe the object-oriented features of the Java language? (Choose three.)

  1. Objects can be reused.
  2. A subclass must override the methods from a superclass.
  3. Objects can share behaviors with other objects.
  4. A package must contain a main class.
  5. Object is the root class of all other objects.
  6. A main method must be declared in every class.
Show answer and explanation

Correct answer: A, C, E. Objects can be reused; Objects can share behaviors with other objects; Object is the root class of all other objects.

The three correct OO features are: A) Objects can be reused through instantiation and composition, promoting code reuse; C) Objects share behaviors through inheritance and interface implementation; and E) Object is the root class of all Java classes in the inheritance hierarchy. Option B is incorrect because subclasses are not required to override superclass methods, they inherit them by default. Option D is incorrect because packages do not require a main class. Option F is incorrect because a main method is only required in the class that serves as the entry point for execution, not in every class.

Why the other options are wrong

  • B. Subclasses inherit superclass methods and are not required to override them unless behavior modification is needed.
  • D. Packages are containers for classes and do not require any specific main class to exist.
  • F. Only the entry point class of an application needs a main method; most classes do not require one.

Question 6

Which one of the following code examples uses valid Java syntax?

  1. Option A
  2. Option B
  3. Option C
  4. Option D
Show answer and explanation

Correct answer: A. Option A

Option A uses valid Java syntax with the correct main method signature: public static void main (String [] args). Option B has invalid syntax because the main method is missing the static keyword, which is required for the entry point of a Java program. Option C uses valid syntax for the main method signature (public void main), but this is not the standard main method that the JVM recognizes as an entry point, the JVM specifically requires the static keyword. Option D has invalid syntax because the parameter declaration uses String () args instead of String [] args, with parentheses instead of square brackets for the array notation.

Why the other options are wrong

  • B. Missing the static keyword in the main method signature; non-static main methods cannot serve as program entry points.
  • C. Missing the static keyword; while syntactically valid as a method, it is not recognized by the JVM as the executable entry point.
  • D. Uses incorrect array syntax String () args instead of String [] args; parentheses cannot be used to denote array types in Java.

Question 7

You are developing a banking module. You have developed a class named ccMask that has a maskcc method. Given the code fragment: You must ensure that the maskcc method returns a string that hides all digits of the credit card number except the four last digits (and the hyphens that separate each group of four digits). Which two code fragments should you use at line n1, independently, to achieve this requirement? (Choose two.)

  1. Option A
  2. Option B
  3. Option C
  4. Option D
Show answer and explanation

Correct answer: B, C. Option B; Option C

The maskcc method needs to return a string with all digits masked except the last four digits, while preserving hyphens. Option B uses substring(15, 19) to extract the last 4 digits from the credit card string "1234-5678-9101-1121" and concatenates them with the template string x ("xxxx-xxxx-xxxx-"), producing "xxxx-xxxx-xxxx-1121". Option C creates a StringBuilder from template x, then appends characters from positions 15-19 of the credit card, and converts to string, achieving the same masked result. Both options correctly isolate and return only the final four digits with the hyphen-separated format intact.

Why the other options are wrong

  • A. This option uses substring(15, 19) on the StringBuilder created from creditCard, but StringBuilder.substring() doesn't exist; this would cause a compilation error.
  • D. This option inserts the entire template x at position 0 of a StringBuilder created from creditCard, resulting in duplication and an incorrect output format rather than the required mask.

Question 8

Which statement will empty the contents of a StringBuilder variable named sb?

  1. sb. deleteAll ();
  2. sb. delete (0, sb. size () );
  3. sb. delete (0, sb. length () );
  4. sb. removeAll ();
Show answer and explanation

Correct answer: C. sb. delete (0, sb. length () );

The delete method of StringBuilder removes characters from a specified range. To empty the entire StringBuilder, you call delete(0, sb.length()), which removes all characters from index 0 to the end of the string. The length() method returns the current length of the StringBuilder.

Why the other options are wrong

  • A. StringBuilder does not have a deleteAll() method.
  • B. StringBuilder does not have a size() method; length() is the correct method to get the string length.
  • D. StringBuilder does not have a removeAll() method.

Question 9

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 mandatory.
  3. Its case label literals can be changed at runtime.
  4. Its expression must evaluate to a single value.
Show answer and explanation

Correct answer: D. Its expression must evaluate to a single value.

A switch statement's expression must evaluate to a single value that can be compared against the case labels. This value is evaluated once and then compared to each case literal to determine which block should execute. The switch expression itself must produce a single result.

Why the other options are wrong

  • A. The default section is optional; a switch statement can function without it.
  • B. The break statement is not mandatory; without it, execution falls through to the next case, which is sometimes intentional.
  • C. Case label literals are compile-time constants and cannot be changed at runtime.

Question 10

Which two code fragments cause a compilation error? (Choose two.)

  1. float flt = 100.00F;
  2. float flt = (float) 1_11.00;
  3. Float flt = 100.00;
  4. double y1 = 203.22; float flt = y1;
  5. int y2 = 100; float flt = (float) y2 ;
Show answer and explanation

Correct answer: C, D. Float flt = 100.00;; double y1 = 203.22; float flt = y1;

Float flt = 100.00 causes a compilation error because 100.00 is a double literal, and assigning a double to a Float (wrapper class) requires explicit casting. Double y1 = 203.22; float flt = y1 causes a compilation error because assigning a double primitive to a float primitive requires explicit casting; the assignment is not automatically performed.

Why the other options are wrong

  • A. float flt = 100.00F is valid; the F suffix explicitly marks the literal as a float.
  • B. float flt = (float) 1_11.00 is valid; the explicit cast and underscores in numeric literals are both allowed.
  • E. int y2 = 100; float flt = (float) y2 is valid; the explicit cast allows the int to be converted to float.

What people say about the full 1Z0-808 pack 5.0 from 1

This programming exam was challenging but approachable with the right materials. Exam questions gave good practice and helped me focus on key Java concepts efficiently. The practice questions was practical.
Deborah Olsen1Z0-808

Question 11

Which statement is true about Java byte code?

  1. It can run on any platform.
  2. It can run on any platform only if it was compiled for that platform.
  3. It can run on any platform that has the Java Runtime Environment.
  4. It can run on any platform that has a Java compiler.
  5. It can run on any platform only if that platform has both the Java Runtime Environment and a Java compiler.
Show answer and explanation

Correct answer: C. It can run on any platform that has the Java Runtime Environment.

Java bytecode is platform-independent intermediate code that runs on the Java Virtual Machine (JVM). It can execute on any platform that has the Java Runtime Environment installed, which contains the JVM needed to interpret and execute the bytecode. This is the core principle of Java's "write once, run anywhere" philosophy.

Why the other options are wrong

  • A. Bytecode alone cannot run without a JVM present on the platform.
  • B. Bytecode is compiled once and does not need to be recompiled for different platforms.
  • D. A Java compiler is needed to create bytecode, not to run it; only the JRE is required for execution.
  • E. Only the JRE is necessary to run bytecode; a compiler is not needed on the target platform.

Question 12

Which two are benefits of polymorphism? (Choose two.)

  1. Faster code at runtime
  2. More efficient code at runtime
  3. More dynamic code at runtime
  4. More flexible and reusable code
  5. Code that is protected from extension by other classes
Show answer and explanation

Correct answer: B, D. More efficient code at runtime; More flexible and reusable code

Polymorphism enables more efficient code at runtime by allowing the JVM to make optimized decisions about which method to call based on object type at execution time, and it provides more flexible and reusable code by allowing objects of different types to be treated through a common interface, reducing code duplication and enabling easier maintenance and extension.

Why the other options are wrong

  • A. Polymorphism does not inherently make code faster; dynamic dispatch adds a small overhead.
  • C. While polymorphic code can be dynamic, this is not typically cited as a primary benefit.
  • E. Polymorphism actually enables extension by other classes through method overriding, not protection from it.

Question 13

Given the code fragment: And given the requirements: 1. Process all the elements of the array in the order of entry. 2. Process all the elements of the array in the reverse order of entry. 3. Process alternating elements of the array in the order of entry. Which two statements are true? (Choose two.)

  1. Requirements 1, 2, and 3 can be implemented by using the enhanced for loop.
  2. Requirements 1, 2, and 3 can be implemented by using the standard for loop.
  3. Requirements 2 and 3 CANNOT be implemented by using the standard for loop.
  4. Requirement 1 can be implemented by using the enhanced for loop.
  5. Requirement 3 CANNOT be implemented by using either the enhanced for loop or the standard for loop.
Show answer and explanation

Correct answer: B, D. Requirements 1, 2, and 3 can be implemented by using the standard for loop; Requirement 1 can be implemented by using the enhanced for loop.

Requirement 1 (process elements in order) can be implemented with both enhanced for loops and standard for loops. The enhanced for loop is specifically designed for this purpose. Requirement 2 (reverse order) requires index-based access to traverse from end to beginning, which only the standard for loop can accomplish, the enhanced for loop cannot be used to reverse iteration. Requirement 3 (alternating elements) requires index control to skip elements (e.g., i += 2), which only the standard for loop can provide. Therefore, option B is correct because the standard for loop can implement all three requirements through flexible index manipulation. Option D is correct because the enhanced for loop can implement requirement 1 (sequential processing). Options A, C, and E are incorrect because the enhanced for loop cannot implement requirements 2 or 3, and both loop types actually can implement requirement 3 with proper index control.

Why the other options are wrong

  • A. The enhanced for loop cannot implement requirements 2 and 3 because it lacks index control.
  • C. Requirement 2 cannot be implemented by the standard for loop is false; you can use a standard for loop with descending index (i--) to process in reverse.
  • E. Requirement 3 can be implemented by the standard for loop using controlled index increments (i += 2), making this statement false.

Question 14

Which three statements are true about the structure of a Java class? (Choose three.)

  1. A public class must have a main method.
  2. A class can have only one private constructor.
  3. A method can have the same name as a field.
  4. A class can have overloaded static methods.
  5. The methods are mandatory components of a class.
  6. The fields need not be initialized before use.
Show answer and explanation

Correct answer: C, D, F. A method can have the same name as a field; A class can have overloaded static methods; The fields need not be initialized before use.

Fields and methods are in separate namespaces, so a method can share a field's name. Static methods can be overloaded like any other method. Fields are automatically given default values such as 0, false or null, so they do not need explicit initialization before use.

Why the other options are wrong

  • A. Only a class used as a program's entry point needs a main method.
  • B. A class can declare several overloaded private constructors.
  • E. A class can compile with no methods at all.

Question 15

Given the following class declarations: • public abstract class Animal • public interface Hunter • public class Cat extends Animal implements Hunter • public class Tiger extends Cat Which answer fails to compile?

  1. Option A
  2. Option B
  3. Option C
  4. Option D
  5. Option E
Show answer and explanation

Correct answer: D. Option D

Option D declares ArrayList<Tiger> but attempts to add a Cat object. While Cat is a superclass of Tiger in the inheritance hierarchy, generics do not support covariance in this way. The ArrayList is explicitly typed to hold Tiger objects, and Cat is not a Tiger, it's the other way around. The add method expects a Tiger (or subtype of Tiger), but Cat, despite being a superclass, cannot be added to an ArrayList<Tiger>. Options A, B, C, and E all compile correctly: A uses ArrayList<Animal> and adds Tiger (valid); B uses ArrayList<Hunter> and adds Cat which implements Hunter (valid); C uses ArrayList<Hunter> and adds Tiger which is a Cat that implements Hunter (valid); E uses ArrayList<Animal> and adds Cat which extends Animal (valid).

Why the other options are wrong

  • A. Compiles because Tiger is an Animal through inheritance, so adding Tiger to ArrayList<Animal> is valid.
  • B. Compiles because Cat implements Hunter, so adding Cat to ArrayList<Hunter> is valid.
  • C. Compiles because Tiger extends Cat which implements Hunter, so Tiger can be added to ArrayList<Hunter>.
  • E. Compiles because Cat extends Animal, so adding Cat to ArrayList<Animal> is valid.

Question 16

Given: And given the code fragment: Book book1 = new EBook(); book1.readBook(); Which option enables the code to compile?

  1. Option A
  2. Option B
  3. Option C
  4. Option D
Show answer and explanation

Correct answer: D. Option D

The code declares `Book book1 = new EBook()` and calls `book1.readBook()`. For this to compile, the `readBook()` method must be accessible through the Book type. Currently, Book is abstract and implements Readable, but `readBook()` is only declared in the Readable interface, it is not implemented in the abstract Book class itself. Option D adds `public void setBookMark() { }` to line n4 in the EBook class, which allows EBook to be instantiated as a concrete class. More critically, for the original code to work, Book must have a concrete implementation of `readBook()`. Option D ensures EBook properly implements all required methods, making it a valid concrete class that can be instantiated. The `readBook()` method is already implemented in EBook (shown at line n4 in the original code), so EBook can be instantiated, and the polymorphic call through the Book reference will work correctly.

Why the other options are wrong

  • A. Changing line n1 from 'abstract class Book' to 'class Book' makes Book concrete but Book still doesn't implement the setBookMark() method from the Readable interface, causing a compilation error.
  • B. Adding an abstract setBookMark() method at line n2 doesn't resolve the core issue; Book remains abstract and cannot be instantiated as `new EBook()` (EBook would still need to implement setBookMark).
  • C. Making EBook abstract with this change prevents EBook from being instantiated at all, causing `new EBook()` to fail compilation.

Question 17

Given the code fragment: And given the requirements: • If the value of the qty variable is greater than or equal to 90, discount = 0.5 • If the value of the qty variable is between 80 and 90, discount = 0.2 Which two code fragments can be independently placed at line n1 to meet the requirements? (Choose two.)

  1. Option A
  2. Option B
  3. Option C
  4. Option D
  5. Option E
Show answer and explanation

Correct answer: A, C. Option A; Option C

Option A uses sequential if statements that correctly assign discount = 0.5 when qty >= 90, and discount = 0.2 when qty is between 80 and 90 (qty > 80 && qty < 90). Option C uses nested ternary operators that properly evaluate the conditions: first checking if qty >= 90 for 0.5, then checking if qty > 80 for 0.2, otherwise 0. Both options correctly implement the requirements that qty >= 90 receives 0.5 discount and qty between 80-90 receives 0.2 discount.

Why the other options are wrong

  • B. Option B assigns discount twice independently without proper nesting, so the second assignment (qty > 80 ? 0.2 : 0) would overwrite the first assignment when qty >= 90, resulting in incorrect logic.
  • D. Option D contains a logic error in the condition: it checks (qty > 80 && qty < 90) which excludes qty = 90, leaving the case where qty = 90 to default to discount = 0 before the second if statement corrects it, making the code unnecessarily convoluted and inefficient.
  • E. Option E uses (qty > 80) in the first ternary check instead of (qty >= 80), which fails to handle the boundary case where qty = 80 correctly, and the nested ternary logic does not properly distinguish between the 80-90 range and the >= 90 range.

That was 17 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

Not ready yet? Get the first 103 free as one PDF by email. Get the Half Pack →