Which of the following is NOT a primitive data type in Java?
double
boolean
String
int
What are method parameters used for?
To define the method's return type
To pass data into a method
To declare variables within a method
To control the method's access level
What will be the value of 'x' after executing the following Java code snippet?
int x = 5; x = x++ + ++x;
12
10
11
The code will result in a compilation error.
What is the base class for all checked exceptions in Java?
Exception
RuntimeException
Throwable
Error
Which method is used to remove an element at a specific index from an ArrayList?
discard()
remove()
extract()
delete()
What is the parent class of all exception classes in Java?
What is the correct way to declare a variable in Java?
int x;
int x = 10
x int = 10;
x = 10;
Which of the following is NOT a valid way to declare an array in Java?
int arr[];
int[] arr;
int arr[] = new int[5];
int []arr;
Which access modifier allows a subclass in a different package to access a member of its superclass?
private
public
protected
default
What will be the output of the following code snippet?
ArrayList<String> list = new ArrayList<>(); list.add("apple"); list.add("banana"); System.out.println(list.get(1));
null
IndexOutOfBoundsException
banana
apple