9 Free Practice Questions for 1Z0-808 Certification
All 9 questions shown below with complete explanations
This practice test covers a mixed set of OCA Java SE 8 topics including Inheritance, Varargs, Collections (ArrayList), and Access Modifiers. These topics appear frequently across the real 1Z0-808 exam.
π‘ Note: This page shows 9 carefully selected questions Each question includes detailed explanations and matches the real OCA exam format.
The correct syntax is 'type... variableName'. The ellipsis (...) must appear between the type and variable name, like int... values.
Option A: public void display(int values...) - INCORRECT. The ellipsis is placed AFTER the variable name. Correct syntax requires ellipsis between type and name. This causes compilation error: 'invalid method declaration; return type required'. The compiler interprets 'values...' as invalid syntax.
Option B: public void display(int... values) - CORRECT. This is the proper varargs syntax. Type (int) followed by ellipsis (...) followed by variable name (values). The ellipsis is correctly positioned between type and name. Inside the method, values is treated as int[].
Option C: public void display(...int values) - INCORRECT. The ellipsis appears BEFORE the type. This is completely invalid syntax. Compilation error: 'illegal start of type'. Java doesn't recognize ... as valid at this position.
Option D: public void display(int values[]) - INCORRECT. This declares a regular array parameter, NOT varargs. Syntax is valid but it's an array, not varargs.
The varargs parameter is treated as an array inside the method. Since three arguments (5, 10, 15) are passed, values.length returns 3.
The output is: 3
You are calling:
displayValues(5, 10, 15);
The method signature is:
static void displayValues(int... values)
A varargs parameter (int...) collects all passed arguments into an array.
So here: values = {5, 10, 15}
Which means: values.length == 3
Thus the print statement:
System.out.println(values.length);
prints: 3
ArrayList is part of the Collections Framework.
All core collection classes (ArrayList, HashMap, HashSet, etc.) live in java.util.
Therefore, the correct package is java.util.
ArrayList is a resizable array implementation of the List interface.
The entire Collections Framework (List, Set, Map, Queue, etc.) resides inside the java.util package.
Option A (java.io) is for input/output classes like File, PrintStream, Reader, etc.
Option C (java.lang) contains core classes like String, Math, Object β not collections.
Option D (java.collection) is not even a real package in Java.
Only java.util.ArrayList is correct and exists in the JDK.
Therefore, answer B is correct.
ArrayList can grow and shrink dynamically as elements are added or removed, unlike arrays which have fixed size.
Unlike arrays which have a fixed length once declared, an ArrayList automatically resizes when new elements are added or removed.
This makes it more flexible for collections where the number of elements can change.
Key differences between Array and ArrayList:
Size: Arrays have fixed size. ArrayList has dynamic size
Type: Arrays can store primitives and objects (int[], String[]).
ArrayList can only store objects (ArrayList
Primitives must be wrapped (Integer, not int).
Syntax: Arrays use brackets (arr[0], arr.length). ArrayList uses methods (list.get(0), list.size()).
Performance: Arrays are faster for fixed-size collections.
ArrayList has overhead for resizing but more convenient.
Functionality: Arrays have basic operations only.
ArrayList has rich API (add, remove, contains, indexOf, etc.).
Memory: Arrays are more memory efficient.
ArrayList uses more memory due to internal array and metadata.
Option A is incorrect - Arrays cannot grow dynamically. Once created, array size is fixed.
Option B is incorrect - ArrayList is NOT fixed size, it grows dynamically.
Option D is incorrect - Arrays can store both primitives and objects, not just primitives.
Option D fails . Value is an instance variable, not a static variable.
Parent.value tries to access an instance variable using class syntax, which is illegal.
Instance variables must be accessed through an object reference, not a class name.
The value field in Parent is a protected instance variable, meaning it belongs to objects, not the class itself.
Accessing instance fields must always be done using an object reference like ref.value, not using Parent.value.
count is static, so it can be accessed with either Child.count or ref.count (even though ref.count is discouraged, it compiles).
Option A compiles because value is inherited and accessible through the object reference ref.
Option B compiles because count is static and inherited by Child.
Option C compiles because static fields can be accessed via objects, even though it's poor style. Option D fails because it violates static access rules.
A method may declare only one varargs parameter, and it must appear last in the parameter list. This is because the varargs parameter collects all remaining arguments, so placing anything after it would make the parameter list ambiguous and cause a compilation error.
In Java, a method can have only one varargs parameter, and it must appear last in the parameter list.
This rule exists because varargs absorb all remaining arguments into an array.
If varargs were not last, the compiler would not know how many arguments belong to it and how many belong to subsequent parameters.
For example:
void test(int... nums, String s) {} // invalid
because nums would capture everything, leaving nothing predictable for s.
Correct declarations place varargs at the end, such as:
void test(String prefix, int... values); // valid
Therefore, options A, B, and D violate Java's varargs rules, making C the only correct choice.
remove(1) removes the element at index 1, which is 20. For ArrayList
ArrayList has two remove() methods: remove(int index) removes element at specified index, and remove(Object o) removes first occurrence of specified object. When an int literal is passed to remove() on ArrayList
What happens here
Since youβre passing an int literal (1), Java chooses:
remove(int index), not remove(Object o).
That means:
It removes the element at index 1, i.e. the second element (20).
Result
After the call:
list = [10, 30]
ArrayList is not thread-safe unless you explicitly wrap it.
It does not synchronize internally.
It also does not use locks like ConcurrentLock.
Javaβs ArrayList is designed for fast, single-threaded access. ArrayList is not thread-safe by default. Multiple threads accessing the same ArrayList concurrently can cause data corruption or Concurrent Modification Exception.
To make an ArrayList thread-safe, you must wrap it:
List list = Collections.synchronizedList(new ArrayList<>());
Option A is incorrect - ArrayList is NOT thread-safe by default.
Option B is incorrect - ArrayList is NOT synchronized internally, unlike Vector which is.
Option C is CORRECT - ArrayList is not synchronized, requires external synchronization.
Option D is incorrect - ArrayList doesn't use ConcurrentLock. Some concurrent collections use locks, but ArrayList doesn't.
None of the statements are correct based on Java's access modifier rules.
Option A is false because the private modifier cannot be applied to top-level classes (classes defined in their own .java file). Top-level classes can only be public or have default (package-private) access. private can be used with inner or nested classes, but not with every class.
Option B is false because the protected modifier cannot be applied to top-level classes.
Option C is false because access modifiers cannot be used inside a method body at all. Local variables within a method have no access modifiers and are scoped only to that method. You cannot write private int x = 5; or public int y = 10; inside a method body - this causes compilation errors.
Option D is false because default access (package-private) is MORE restrictive than protected, not less. Default access is accessible only within the same package, while protected access is accessible within the same package AND by subclasses in different packages through inheritance.
Therefore, the correct answer is E - None of the above statements are correct.
Access all 1624 questions covering all OCA topics
β 1,624 practice questions
β 29 full certification tests
β Chapter-wise practice exams
β Detailed explanations for every answer
β Progress tracking & certificates