Which statement about the 'final' keyword is correct when applied to a class?
The final keyword prevents a class from being extended. When a class is declared final, no subclass can inherit from it.
Oracle Certification
59 practice questions with correct answers and detailed explanations. Use this guide to review concepts before taking the practice 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.
Which statement about the 'final' keyword is correct when applied to a class?
The final keyword prevents a class from being extended. When a class is declared final, no subclass can inherit from it.
What will be printed when the following code is executed? int x = 5; System.out.println(x++ + ++x);
x++ returns 5 (then x becomes 6), ++x increments x to 7 and returns 7. So 5 + 7 = 12.
Which of the following is a valid way to declare and initialize a two-dimensional array in Java?
Java allows jagged arrays where rows can have different lengths. Option A correctly declares a 2D array and initializes the first row.
What is the output of the following code? String s1 = new String("test"); String s2 = new String("test"); System.out.println(s1 == s2);
The == operator compares references, not content. s1 and s2 point to different String objects in memory, so the result is false.
Which method must be overridden when implementing the Comparable interface?
The Comparable interface requires implementing the compareTo() method, which returns an int indicating the ordering relationship.
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] + " "); }
The continue statement skips iteration when i == 2, so it prints 1, 2, 4, 5 (skipping the element at index 2, which is 3).
Which of the following correctly describes the behavior of the default constructor?
Java automatically provides a no-argument default constructor only if no explicit constructors are defined in the class.
What is the output of the following code? String str = "Hello"; str = str.concat(" World"); System.out.println(str);
The concat() method returns a new String with the concatenated value. The result is assigned back to str and printed.
Which statement about static methods is correct?
Static methods belong to the class itself rather than to instances. They can be called without creating an object and cannot access instance variables.
What will be printed by the following code? int x = 10; int y = 20; int z = (x > y) ? x : y; System.out.println(z);
The ternary operator (condition ? valueIfTrue : valueIfFalse) evaluates the condition x > y as false, so it returns y, which is 20.
Which of the following best describes the purpose of the 'super' keyword?
The super keyword allows a child class to access parent class members and constructors, enabling proper inheritance patterns.
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(); }
The nested loop prints: first iteration prints '1', second prints '12', third prints '123', each on a new line due to println().
Which interface would you implement to make an object's instances sortable using the Collections.sort() method?
The Comparable interface's compareTo() method defines the natural ordering of objects, allowing Collections.sort() to sort them.
What will this code print? int num = 5; num += 3; System.out.println(num);
The compound assignment operator += adds 3 to num (5 + 3 = 8).
Which of the following statements about method overloading is true?
Method overloading requires the same method name but different parameter lists (number, type, or order of parameters).
What will be printed when this code executes? String[] arr = {"A", "B", "C"}; for (String s : arr) { System.out.print(s + " "); }
The enhanced for loop iterates through each element and prints it followed by a space.
Which statement correctly describes exception handling in Java?
When using multiple catch blocks, they must be ordered from most specific (child exceptions) to most general (parent exceptions) or a compilation error occurs.
What is the output of the following code? int a = 5; int b = 2; System.out.println(a / b);
Both a and b are integers, so integer division is performed. 5 / 2 = 2 (the decimal part is truncated).
Which of the following is true regarding access modifiers in Java?
Protected access allows visibility within the same package and to subclasses, regardless of whether the subclass is in a different package.
What will be the result of the following code? boolean flag = true; if (flag = false) { System.out.println("True"); } else { System.out.println("False"); }
The assignment operator (=) assigns false to flag and returns false, so the else block executes and prints 'False'.
Which of the following correctly describes the behavior of the equals() method?
The equals() method can be overridden to compare object content. When using objects in hash-based collections, hashCode() should also be overridden consistently.
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);
The enhanced for loop iterates through each element and adds it to sum: 10 + 20 + 30 = 60.
Which statement best describes the relationship between the abstract class and interfaces?
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.
What will be printed by the following code? String s = "Java"; s = s.toUpperCase(); System.out.println(s);
The toUpperCase() method returns a new String with all characters converted to uppercase, which is 'JAVA'.
Which of the following statements about variable scope is correct?
Static variables are class-level variables shared by all instances and retain their value across the entire program's execution.
Which of the following is a valid Java identifier?
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).
What is the output of the following code snippet? int x = 5; int y = ++x + x++; System.out.println(x + " " + y);
++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.
Which statement about the default constructor is true?
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.
What is the result of the following expression? boolean result = (5 > 3) && (2 < 1) || (4 == 4);
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.
Which of the following will compile and run without throwing an exception?
Option A throws NullPointerException, B throws ArrayIndexOutOfBoundsException, C throws ArithmeticException. Option D safely unboxes the Integer to int via auto-unboxing.
What is the scope of a variable declared inside a method?
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.
Which of the following correctly demonstrates method overloading?
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.
What will be printed by the following code? for (int i = 0; i < 3; i++) { if (i == 1) continue; System.out.print(i + " "); }
The loop iterates with i = 0, 1, 2. When i == 1, continue skips the print statement. Only i = 0 and i = 2 are printed.
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));
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.
Which access modifier allows a variable to be accessed from any class?
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.
What is the output of this code? int[] numbers = {1, 2, 3}; for (int num : numbers) { num = num * 2; } System.out.println(numbers[0]);
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.
Which statement correctly describes static variables?
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.
Consider the following class hierarchy: class Animal { } class Dog extends Animal { }. Which statement is correct?
This demonstrates polymorphism through upcasting. A superclass reference can safely hold a subclass object. The reverse (option B) is invalid without explicit casting.
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); } }
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.
What is the result of executing the following code? String s = "Java"; s.concat(" Programming"); System.out.println(s);
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.
Which of the following is NOT a primitive data type in Java?
String is a reference type (class), not a primitive. The eight primitive types are: byte, short, int, long, float, double, boolean, and char.
What does the following code output? int a = 5; int b = a++ + ++a; System.out.println(a + " " + b);
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.
Which of the following best describes encapsulation?
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.
What is the output of the following code? int x = 0; while (x < 5) { x++; if (x == 3) break; } System.out.println(x);
The loop increments x to 1, 2, then 3. When x == 3, the break statement exits the loop. x is 3 when printed.
Consider the following method signature: public static void printMessage(String... messages). What does the '...' syntax indicate?
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.
Which of the following statements about the 'final' keyword is correct?
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.
What is the output of the following code? String str = "Hello"; String result = (str == null) ? "Null" : "Not Null"; System.out.println(result);
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.
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);
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.
Which of the following best explains the purpose of the 'super' keyword?
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.
Which statement about the final keyword is correct?
The final keyword prevents method overriding in subclasses. Final classes cannot be extended, and final variables cannot be reassigned after initialization.
What is the output of the following code? String s = "Hello"; s.concat(" World"); System.out.println(s);
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'.
Which of the following correctly declares a two-dimensional array of integers in Java?
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].
What will be printed when the following code is executed? int x = 5; int y = ++x + x++; System.out.println(x + " " + y);
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.
Which interface must be implemented to allow an object to be used in an enhanced for-loop?
The Iterable interface is required for enhanced for-loops (for-each loops). It provides the iterator() method which returns an Iterator for traversing elements.
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"); }
Division by zero throws ArithmeticException, which is caught and prints 'Caught'. The finally block always executes regardless of exception handling, printing 'Finally'.
Which of the following statements about ArrayList is true?
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().
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] + " "); }
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.
Which of the following best describes method overloading in Java?
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.
Given the following code, what is the output? String str = "Java"; str = str.toLowerCase(); str = str.replace('a', 'u'); System.out.println(str);
First, toLowerCase() converts 'Java' to 'java'. Then replace('a', 'u') replaces all 'a' characters with 'u', resulting in 'juvu'.
You've reviewed all 59 questions. Take the interactive practice exam to simulate the real test environment.
▶ Start Practice Exam — Free