Which keyword is used to explicitly throw an exception in Java?
throw
catch
finally
try
What is the purpose of the 'switch' statement in Java?
To declare a variable
To execute a block of code repeatedly
To define a method
To check a condition and execute different code blocks based on the result
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;
Can a class have multiple constructors?
Yes, but they must have the same parameter list.
Yes, as long as they have different parameter lists.
Constructors are optional, so a class may or may not have any.
No, a class can only have one constructor.
Which component of the Java Development Kit (JDK) is responsible for converting Java source code (.java files) into bytecode (.class files)?
Java Runtime Environment (JRE)
Integrated Development Environment (IDE)
Java Compiler (javac)
Java Virtual Machine (JVM)
What is the primary purpose of a method in Java?
To perform a specific task
To control program flow
To define a class
To store data
Which method is used to add an element to the end of an ArrayList?
insert()
push()
add()
append()
What is the primary purpose of a constructor in Java?
To define methods
To initialize object attributes
To control access to class members
To declare variables
What are method parameters used for?
To define the method's return type
To pass data into a method
To control the method's access level
To declare variables within a method
What is the base class for all checked exceptions in Java?
RuntimeException
Throwable
Exception
Error