Which access modifier allows a subclass in a different package to access a member of its superclass?
default
public
private
protected
Which keyword is used to explicitly throw an exception in Java?
try
catch
finally
throw
What is the correct way to declare a variable in Java?
int x = 10
int x;
x = 10;
x int = 10;
Which component of the Java Development Kit (JDK) is responsible for converting Java source code (.java files) into bytecode (.class files)?
Integrated Development Environment (IDE)
Java Virtual Machine (JVM)
Java Runtime Environment (JRE)
Java Compiler (javac)
What will happen if you try to access an element at an invalid index in an ArrayList?
It will throw an ArrayIndexOutOfBoundsException.
The program will crash.
It will return null.
It will throw a NullPointerException.
What is the output of the following code snippet?
int x = 5; if (x > 10) { System.out.println("Greater than 10"); } else { System.out.println("Less than or equal to 10"); }
Less than or equal to 10
x is 5
Greater than 10
Error
What is the parent class of all exception classes in Java?
RuntimeException
Exception
Throwable
Which of the following is NOT a valid access modifier in Java?
static
If a method in Java is declared 'private,' where can it be accessed?
From subclasses, even in different packages
From any class within the same package
Only from within the same class
From any class in the application
What are method parameters used for?
To pass data into a method
To control the method's access level
To declare variables within a method
To define the method's return type