What will be the value of 'x' after executing the following Java code snippet?
int x = 5; x = x++ + ++x;
12
The code will result in a compilation error.
10
11
Which of the following is NOT a valid way to declare an array in Java?
int arr[];
int []arr;
int[] arr;
int arr[] = new int[5];
Which of the following is NOT a primitive data type in Java?
boolean
double
String
int
What is the process of calling a method in Java?
Creating an object of the class
Declaring the method's return type
Defining the method body
Using the method's name followed by parentheses
What is the primary difference between an array and an ArrayList in Java?
Arrays are fixed in size, while ArrayLists are dynamically sized.
Arrays can store objects of different classes, while ArrayLists can only store objects of the same class.
Arrays can store primitive data types, while ArrayLists cannot.
Arrays are part of the Java Collections Framework, while ArrayLists are not.
Which access modifier allows a subclass in a different package to access a member of its superclass?
private
default
public
protected
What is the purpose of the 'break' statement in a Java 'switch' statement?
It terminates the entire program.
It skips the current iteration of a loop.
It prints an error message to the console.
It exits the 'switch' block after a matching case is found.
Which method is used to add an element to the end of an ArrayList?
insert()
append()
push()
add()
Which operator is used for string concatenation in Java?
/
What is the role of parameters in a Java method?
To define the method's return type.
To control the method's visibility.
To provide input values to the method.
To declare variables within the method.