Oracle Certification

1Z0-808 — Java Associate Study Guide

59 practice questions with correct answers and detailed explanations. Use this guide to review concepts before taking the practice exam.

▶ Take Practice Exam 59 questions  ·  Free  ·  No registration

About the 1Z0-808 Exam

The Oracle Java Associate (1Z0-808) certification validates professional expertise in Oracle technologies. This study guide covers all 59 practice questions from our 1Z0-808 practice test, complete with correct answers and explanations to help you understand each concept thoroughly.

Review each question and explanation below, then test yourself with the full interactive practice exam to measure your readiness.

59 Practice Questions & Answers

Q1 Medium

Which statement about the 'final' keyword is correct when applied to a class?

  • A A final class must implement all abstract methods
  • B A final class cannot be extended by any subclass ✓ Correct
  • C A final class automatically becomes immutable
  • D A final class can still be extended by using composition
Explanation

The final keyword prevents a class from being extended. When a class is declared final, no subclass can inherit from it.

Q2 Medium

What will be printed when the following code is executed? int x = 5; System.out.println(x++ + ++x);

  • A 11
  • B 12 ✓ Correct
  • C 13
  • D 10
Explanation

x++ returns 5 (then x becomes 6), ++x increments x to 7 and returns 7. So 5 + 7 = 12.

Q3 Medium

Which of the following is a valid way to declare and initialize a two-dimensional array in Java?

  • A int[][] arr = new int[3];
  • B int[][] arr = {1, 2, 3};
  • C int[][] arr = new int[3][]; arr[0] = new int[]{1, 2, 3}; ✓ Correct
  • D int[][] arr = new int[][3];
Explanation

Java allows jagged arrays where rows can have different lengths. Option A correctly declares a 2D array and initializes the first row.

Q4 Easy

What is the output of the following code? String s1 = new String("test"); String s2 = new String("test"); System.out.println(s1 == s2);

  • A null
  • B true
  • C false ✓ Correct
  • D Compilation error
Explanation

The == operator compares references, not content. s1 and s2 point to different String objects in memory, so the result is false.

Q5 Medium

Which method must be overridden when implementing the Comparable interface?

  • A hashCode()
  • B equals(Object o)
  • C compareTo(Object o) ✓ Correct
  • D compare(Object o1, Object o2)
Explanation

The Comparable interface requires implementing the compareTo() method, which returns an int indicating the ordering relationship.

Q6 Easy

What will be the result of executing the following code? int[] numbers = {1, 2, 3, 4, 5}; for (int i = 0; i < numbers.length; i++) { if (i == 2) continue; System.out.print(numbers[i] + " "); }

  • A 2 4 5
  • B 1 2 4 5 ✓ Correct
  • C 1 2 3 4 5
  • D 1 2 4 5
Explanation

The continue statement skips iteration when i == 2, so it prints 1, 2, 4, 5 (skipping the element at index 2, which is 3).

Q7 Medium

Which of the following correctly describes the behavior of the default constructor?

  • A It is automatically generated only if no other constructors are defined ✓ Correct
  • B It always takes at least one parameter representing the object's state
  • C It initializes all instance variables to their default values and can accept multiple parameters
  • D It is inherited from the Object class and cannot be overridden
Explanation

Java automatically provides a no-argument default constructor only if no explicit constructors are defined in the class.

Q8 Easy

What is the output of the following code? String str = "Hello"; str = str.concat(" World"); System.out.println(str);

  • A null
  • B World
  • C Hello
  • D Hello World ✓ Correct
Explanation

The concat() method returns a new String with the concatenated value. The result is assigned back to str and printed.

Q9 Medium

Which statement about static methods is correct?

  • A Static methods can access instance variables directly without an object reference
  • B Static methods are associated with the class, not with individual instances ✓ Correct
  • C Static methods can be overridden by subclasses to provide different implementations
  • D Static methods must return a value and cannot return void
Explanation

Static methods belong to the class itself rather than to instances. They can be called without creating an object and cannot access instance variables.

Q10 Easy

What will be printed by the following code? int x = 10; int y = 20; int z = (x > y) ? x : y; System.out.println(z);

  • A 10
  • B false
  • C true
  • D 20 ✓ Correct
Explanation

The ternary operator (condition ? valueIfTrue : valueIfFalse) evaluates the condition x > y as false, so it returns y, which is 20.

Q11 Medium

Which of the following best describes the purpose of the 'super' keyword?

  • A To prevent a child class from overriding parent class methods and ensure inheritance of all parent behaviors
  • B To reference members of the parent class or call the parent constructor from a child class ✓ Correct
  • C To create a new instance of the parent class from the child class
  • D To declare that a class should be treated as superior to other classes
Explanation

The super keyword allows a child class to access parent class members and constructors, enabling proper inheritance patterns.

Q12 Medium

What is the output of the following code? for (int i = 1; i <= 3; i++) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); }

  • A 1\n12\n123 ✓ Correct
  • B 1\n21\n321
  • C 1\n1\n1
  • D 123\n123\n123
Explanation

The nested loop prints: first iteration prints '1', second prints '12', third prints '123', each on a new line due to println().

Q13 Medium

Which interface would you implement to make an object's instances sortable using the Collections.sort() method?

  • A Comparable ✓ Correct
  • B Cloneable
  • C Iterable
  • D Serializable
Explanation

The Comparable interface's compareTo() method defines the natural ordering of objects, allowing Collections.sort() to sort them.

Q14 Easy

What will this code print? int num = 5; num += 3; System.out.println(num);

  • A 8 ✓ Correct
  • B 53
  • C 3
  • D 5
Explanation

The compound assignment operator += adds 3 to num (5 + 3 = 8).

Q15 Medium

Which of the following statements about method overloading is true?

  • A Overloaded methods must be in different classes to maintain type safety and polymorphism
  • B Overloaded methods must have different return types to be distinguished by the compiler
  • C Overloading allows a method to have multiple return statements with different return types
  • D Overloaded methods must have the same name but different parameter lists or types ✓ Correct
Explanation

Method overloading requires the same method name but different parameter lists (number, type, or order of parameters).

Q16 Easy

What will be printed when this code executes? String[] arr = {"A", "B", "C"}; for (String s : arr) { System.out.print(s + " "); }

  • A [A, B, C]
  • B A B C ✓ Correct
  • C ABC
  • D A B C
Explanation

The enhanced for loop iterates through each element and prints it followed by a space.

Q17 Hard

Which statement correctly describes exception handling in Java?

  • A Multiple catch blocks can be used, but they must be ordered from most specific to most general exception types ✓ Correct
  • B The finally block is guaranteed to execute before any return statement in the try or catch block only if an exception occurred
  • C Checked exceptions must be caught or declared in the method signature using the throws keyword
  • D Unchecked exceptions must always be caught, or the program will not compile
Explanation

When using multiple catch blocks, they must be ordered from most specific (child exceptions) to most general (parent exceptions) or a compilation error occurs.

Q18 Easy

What is the output of the following code? int a = 5; int b = 2; System.out.println(a / b);

  • A 3
  • B 2.5
  • C 2.0
  • D 2 ✓ Correct
Explanation

Both a and b are integers, so integer division is performed. 5 / 2 = 2 (the decimal part is truncated).

Q19 Hard

Which of the following is true regarding access modifiers in Java?

  • A Package-private members can be accessed from any class in the same package and from all subclasses
  • B Protected members are accessible from subclasses even if they are in different packages ✓ Correct
  • C Private members can be accessed from any class in the same package but not from subclasses
  • D Public members can be accessed only within the same class hierarchy
Explanation

Protected access allows visibility within the same package and to subclasses, regardless of whether the subclass is in a different package.

Q20 Medium

What will be the result of the following code? boolean flag = true; if (flag = false) { System.out.println("True"); } else { System.out.println("False"); }

  • A True
  • B False ✓ Correct
  • C Compilation error
  • D No output
Explanation

The assignment operator (=) assigns false to flag and returns false, so the else block executes and prints 'False'.

Q21 Hard

Which of the following correctly describes the behavior of the equals() method?

  • A It must be implemented by all classes and is automatically called when using the == operator
  • B It can be overridden to compare object content and should be overridden along with hashCode() for proper behavior in collections ✓ Correct
  • C It performs shallow comparison and cannot be used with String objects without compilation errors
  • D It compares object references and is inherited from the Object class without modification for all classes
Explanation

The equals() method can be overridden to compare object content. When using objects in hash-based collections, hashCode() should also be overridden consistently.

Q22 Easy

What is the output of the following code? int[] numbers = {10, 20, 30}; int sum = 0; for (int num : numbers) { sum += num; } System.out.println(sum);

  • A 102030
  • B 20
  • C 60 ✓ Correct
  • D 30
Explanation

The enhanced for loop iterates through each element and adds it to sum: 10 + 20 + 30 = 60.

Q23 Hard

Which statement best describes the relationship between the abstract class and interfaces?

  • A A class can extend only one abstract class but can implement multiple interfaces, and abstract classes can have state while interfaces cannot ✓ Correct
  • B Abstract classes must override all methods from the Object class, while interfaces do not have this requirement
  • C Interfaces provide better encapsulation than abstract classes because they cannot have constructors or instance variables
  • D Abstract classes and interfaces are identical in functionality and serve the same purpose in Java
Explanation

Abstract classes provide structure with state and constructors, while a class can implement multiple interfaces for diverse behaviors. In Java 8+, interfaces can have default methods but still cannot have instance state.

Q24 Easy

What will be printed by the following code? String s = "Java"; s = s.toUpperCase(); System.out.println(s);

  • A Java
  • B JAVA ✓ Correct
  • C java
  • D jAvA
Explanation

The toUpperCase() method returns a new String with all characters converted to uppercase, which is 'JAVA'.

Q25 Hard

Which of the following statements about variable scope is correct?

  • A Instance variables are accessible from static methods without any restrictions or limitations
  • B A variable declared within a for loop is accessible after the loop terminates, provided it was initialized before the loop
  • C Local variables declared in a try block are accessible in the corresponding catch block if an exception occurs
  • D Static variables are shared across all instances of a class and maintain their value throughout the program execution ✓ Correct
Explanation

Static variables are class-level variables shared by all instances and retain their value across the entire program's execution.

Q26 Easy

Which of the following is a valid Java identifier?

  • A _myVar ✓ Correct
  • B 2ndVariable
  • C my-variable
  • D my variable
Explanation

Java identifiers must start with a letter, underscore, or dollar sign. They cannot start with a digit (option A), contain hyphens (option C), or spaces (option D).

Q27 Hard

What is the output of the following code snippet? int x = 5; int y = ++x + x++; System.out.println(x + " " + y);

  • A 7 11
  • B 6 11
  • C 7 12 ✓ Correct
  • D 6 12
Explanation

++x increments x to 6 before use (pre-increment), then x++ uses the current value 6 and increments after. So y = 6 + 6 = 12, and final x = 7.

Q28 Medium

Which statement about the default constructor is true?

  • A A default constructor is always implicitly provided by the Java compiler regardless of whether other constructors exist
  • B If a class defines any constructor, the compiler will provide a default no-argument constructor
  • C A default constructor can be explicitly defined with parameters
  • D The default constructor initializes all instance variables to their default values ✓ Correct
Explanation

The default constructor sets primitive fields to 0/false and object references to null. If any constructor is explicitly defined, no default constructor is generated unless explicitly coded.

Q29 Medium

What is the result of the following expression? boolean result = (5 > 3) && (2 < 1) || (4 == 4);

  • A null
  • B Compilation error
  • C true ✓ Correct
  • D false
Explanation

The && operator has higher precedence than ||. (5 > 3) && (2 < 1) evaluates to false, but false || (4 == 4) evaluates to true because (4 == 4) is true.

Q30 Medium

Which of the following will compile and run without throwing an exception?

  • A int[] arr = new int[5]; arr[5] = 10;
  • B String s = null; int len = s.length();
  • C Integer i = Integer.valueOf("42"); int x = i; ✓ Correct
  • D int x = 10 / 0;
Explanation

Option A throws NullPointerException, B throws ArrayIndexOutOfBoundsException, C throws ArithmeticException. Option D safely unboxes the Integer to int via auto-unboxing.

Q31 Easy

What is the scope of a variable declared inside a method?

  • A Local scope; it exists only within the method ✓ Correct
  • B Class scope; it is accessible throughout the class
  • C Package scope; it is accessible throughout the package
  • D Global scope; it persists for the lifetime of the application
Explanation

Variables declared inside a method have local scope and are accessible only within that method. They are created when the method is called and destroyed when it returns.

Q32 Medium

Which of the following correctly demonstrates method overloading?

  • A Two methods with the same name, same parameter list, but different return types
  • B Two methods with the same name and different parameter types or counts, in the same class ✓ Correct
  • C Two methods with different names but identical parameter lists in different classes
  • D A child class method with the same name and signature as the parent class method
Explanation

Method overloading requires the same method name but different parameters (type, count, or order). Return type alone does not constitute overloading. Option D describes overriding, not overloading.

Q33 Easy

What will be printed by the following code? for (int i = 0; i < 3; i++) { if (i == 1) continue; System.out.print(i + " "); }

  • A 0 2 ✓ Correct
  • B 0 1 2
  • C 0 1 2 3
  • D 1 2
Explanation

The loop iterates with i = 0, 1, 2. When i == 1, continue skips the print statement. Only i = 0 and i = 2 are printed.

Q34 Medium

Consider the following code. What is the output? String str = "Hello"; String str2 = new String("Hello"); System.out.println(str == str2); System.out.println(str.equals(str2));

  • A true false
  • B false false
  • C true true
  • D false true ✓ Correct
Explanation

The == operator compares object references, not content. str and str2 are different objects, so == returns false. The equals() method compares string content, so it returns true.

Q35 Easy

Which access modifier allows a variable to be accessed from any class?

  • A default (package-private)
  • B private
  • C public ✓ Correct
  • D protected
Explanation

Only public members are accessible from any class in any package. Private restricts to the class, protected to package and subclasses, and default to package only.

Q36 Medium

What is the output of this code? int[] numbers = {1, 2, 3}; for (int num : numbers) { num = num * 2; } System.out.println(numbers[0]);

  • A 4
  • B 2 ✓ Correct
  • C 1
  • D 6
Explanation

The enhanced for loop iterates over array elements by copying their values into the local variable num. Modifying num does not change the array. numbers[0] remains 1, so 1 is printed.

Q37 Medium

Which statement correctly describes static variables?

  • A Static variables must be declared inside a method
  • B Static variables are shared among all instances of a class and exist in memory throughout the program's execution ✓ Correct
  • C Static variables are created for each object instance of a class
  • D Static variables can only store numeric values
Explanation

Static variables belong to the class itself, not individual instances, and are allocated in memory once when the class is loaded. They persist throughout the program's lifetime.

Q38 Medium

Consider the following class hierarchy: class Animal { } class Dog extends Animal { }. Which statement is correct?

  • A You cannot assign a subclass object to a superclass reference variable in Java
  • B Dog myVar = new Animal(); is valid due to polymorphism
  • C Animal myVar = new Dog(); is invalid because Dog is not an Animal
  • D Animal myVar = new Dog(); is valid; a reference to a superclass can hold an object of a subclass type ✓ Correct
Explanation

This demonstrates polymorphism through upcasting. A superclass reference can safely hold a subclass object. The reverse (option B) is invalid without explicit casting.

Q39 Easy

What will happen when you compile and run the following code? public class Test { public static void main(String[] args) { int x = 10; int y = 3; System.out.println(x / y); } }

  • A It will print 3.333...
  • B It will print 3.0
  • C It will throw an ArithmeticException
  • D It will print 3 ✓ Correct
Explanation

Both x and y are integers, so integer division is performed, which truncates the decimal portion. The result is 3, not 3.333 or 3.0.

Q40 Medium

What is the result of executing the following code? String s = "Java"; s.concat(" Programming"); System.out.println(s);

  • A Java ✓ Correct
  • B null
  • C Compilation error
  • D Java Programming
Explanation

Strings in Java are immutable. The concat() method returns a new String object but does not modify the original. Since the result is not assigned to s, the original string remains unchanged.

Q41 Easy

Which of the following is NOT a primitive data type in Java?

  • A long
  • B String ✓ Correct
  • C char
  • D boolean
Explanation

String is a reference type (class), not a primitive. The eight primitive types are: byte, short, int, long, float, double, boolean, and char.

Q42 Hard

What does the following code output? int a = 5; int b = a++ + ++a; System.out.println(a + " " + b);

  • A 6 11
  • B 7 12 ✓ Correct
  • C 6 12
  • D 7 11
Explanation

a++ uses 5 then increments (a becomes 6), ++a pre-increments (a becomes 7) then uses 7. So b = 5 + 7 = 12, and final a = 7.

Q43 Medium

Which of the following best describes encapsulation?

  • A The ability to use the same method name for different types of objects
  • B Bundling data and methods together while hiding internal details from the outside world ✓ Correct
  • C The process of creating multiple objects from a single class definition
  • D The ability of a class to inherit properties from another class
Explanation

Encapsulation involves wrapping data and methods in a class and controlling access using access modifiers. Option A is inheritance, C is instantiation, and D is polymorphism.

Q44 Easy

What is the output of the following code? int x = 0; while (x < 5) { x++; if (x == 3) break; } System.out.println(x);

  • A 3 ✓ Correct
  • B 5
  • C 2
  • D 4
Explanation

The loop increments x to 1, 2, then 3. When x == 3, the break statement exits the loop. x is 3 when printed.

Q45 Medium

Consider the following method signature: public static void printMessage(String... messages). What does the '...' syntax indicate?

  • A This is a syntax error and will not compile
  • B The method requires exactly three String parameters
  • C The method accepts a variable number of String arguments (varargs) ✓ Correct
  • D The method can only be called with null arguments
Explanation

The '...' (ellipsis) syntax represents varargs, allowing a method to accept zero or more arguments of the specified type. Inside the method, messages is treated as an array.

Q46 Medium

Which of the following statements about the 'final' keyword is correct?

  • A A final variable cannot have its value changed after initialization ✓ Correct
  • B The 'final' keyword has no effect when applied to primitive data types
  • C A final method can be overridden in a subclass
  • D A final class can be extended by other classes
Explanation

Once a final variable is initialized, its value cannot be modified. A final class cannot be extended, a final method cannot be overridden, and final applies to both primitives and objects.

Q47 Easy

What is the output of the following code? String str = "Hello"; String result = (str == null) ? "Null" : "Not Null"; System.out.println(result);

  • A Not Null ✓ Correct
  • B HelloNull
  • C Compilation error
  • D Null
Explanation

The ternary operator evaluates the condition (str == null), which is false since str references "Hello". Therefore, the expression after the colon ("Not Null") is returned.

Q48 Easy

Consider the following code. What will be printed? int[] arr = {10, 20, 30, 40}; int sum = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i]; } System.out.println(sum);

  • A 110
  • B 120
  • C 100 ✓ Correct
  • D 90
Explanation

The loop adds all array elements: 10 + 20 + 30 + 40 = 100. The length of the array is 4, and the loop correctly iterates through all four elements.

Q49 Medium

Which of the following best explains the purpose of the 'super' keyword?

  • A It prevents method overriding in subclasses
  • B It allows a subclass to access members of its parent class ✓ Correct
  • C It creates a new instance of the parent class
  • D It refers to the current object instance
Explanation

The 'super' keyword is used to call parent class methods and constructors from a subclass. Option A describes 'this', and option C is incorrect because super doesn't create instances.

Q50 Medium

Which statement about the final keyword is correct?

  • A A final variable can be reassigned multiple times after initialization.
  • B A final method cannot be overridden in subclasses. ✓ Correct
  • C A final class can be extended by other classes.
  • D The final keyword has no effect on method behavior.
Explanation

The final keyword prevents method overriding in subclasses. Final classes cannot be extended, and final variables cannot be reassigned after initialization.

Q51 Medium

What is the output of the following code? String s = "Hello"; s.concat(" World"); System.out.println(s);

  • A Hello World
  • B null
  • C Hello ✓ Correct
  • D A compilation error occurs.
Explanation

Strings are immutable in Java. The concat() method returns a new String but does not modify the original. Since the result is not assigned back to s, the output is still 'Hello'.

Q52 Easy

Which of the following correctly declares a two-dimensional array of integers in Java?

  • A int[][] arr = int[5][10];
  • B int[] arr = new int[5][10];
  • C int[][] arr = new int[5][10]; ✓ Correct
  • D int[5][10] arr = new int[][];
Explanation

Two-dimensional arrays require double brackets in the type declaration. Option B uses the correct syntax with int[][] and proper instantiation with new int[5][10].

Q53 Hard

What will be printed when the following code is executed? int x = 5; int y = ++x + x++; System.out.println(x + " " + y);

  • A 6 11
  • B 7 11
  • C 7 12 ✓ Correct
  • D 6 12
Explanation

The pre-increment ++x increments x to 6 first, then x++ uses 6 and increments to 7. So y = 6 + 6 = 12, and x becomes 7. Output: 7 12.

Q54 Medium

Which interface must be implemented to allow an object to be used in an enhanced for-loop?

  • A Comparable
  • B Iterator
  • C Iterable ✓ Correct
  • D Collection
Explanation

The Iterable interface is required for enhanced for-loops (for-each loops). It provides the iterator() method which returns an Iterator for traversing elements.

Q55 Medium

What is the result of executing the following code? try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println("Caught"); } finally { System.out.println("Finally"); }

  • A Caught
  • B Finally
  • C Caught Finally ✓ Correct
  • D An unhandled exception occurs.
Explanation

Division by zero throws ArithmeticException, which is caught and prints 'Caught'. The finally block always executes regardless of exception handling, printing 'Finally'.

Q56 Medium

Which of the following statements about ArrayList is true?

  • A ArrayList uses a fixed-size internal array and cannot grow dynamically.
  • B ArrayList is a resizable array implementation that allows null values and maintains insertion order. ✓ Correct
  • C ArrayList maintains insertion order and allows duplicate elements, but does not allow null values.
  • D ArrayList is thread-safe and can be safely used in multi-threaded environments without synchronization.
Explanation

ArrayList is a resizable List implementation that maintains insertion order, allows null values, and allows duplicates. It is not thread-safe, unlike Vector or Collections.synchronizedList().

Q57 Medium

What will be the output of the following code? int[] numbers = {1, 2, 3, 4, 5}; for (int i = 0; i < numbers.length; i++) { if (i == 2) continue; System.out.print(numbers[i] + " "); }

  • A 1 2 4 5
  • B 1 2 3 4 5
  • C 1 2 4 5 ✓ Correct
  • D 2 4 5
Explanation

The continue statement skips iteration when i == 2 (which is the number 3). So it prints 1, 2, 4, 5 with spaces. The trailing space after 5 is included from the print statement.

Q58 Medium

Which of the following best describes method overloading in Java?

  • A Creating multiple methods with the same name but different parameter lists in the same or different classes. ✓ Correct
  • B Creating multiple methods with the same name and the same parameter list but different return types.
  • C Creating a method in a subclass that has the same name and signature as a method in the superclass.
  • D Creating multiple constructors with different parameter lists in the same class.
Explanation

Method overloading allows multiple methods with the same name but different parameter lists (number, type, or order of parameters) in the same class. Option D describes constructor overloading, which is a specific case of overloading.

Q59 Easy

Given the following code, what is the output? String str = "Java"; str = str.toLowerCase(); str = str.replace('a', 'u'); System.out.println(str);

  • A juvA
  • B JAVA
  • C juvu ✓ Correct
  • D Java
Explanation

First, toLowerCase() converts 'Java' to 'java'. Then replace('a', 'u') replaces all 'a' characters with 'u', resulting in 'juvu'.

Ready to test your knowledge?

You've reviewed all 59 questions. Take the interactive practice exam to simulate the real test environment.

▶ Start Practice Exam — Free