What is the primary purpose of exception handling in Java?
To improve the performance of Java applications.
To completely prevent runtime errors from occurring.
To enforce strict coding standards and prevent compilation errors.
To provide a mechanism for handling unexpected events during program execution.
Which access modifier allows a subclass in a different package to access a member of its superclass?
private
default
public
protected
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
Can you overload a method in Java by changing only the return type?
No
Yes
What is the correct way to declare a variable in Java?
int x;
x int = 10;
x = 10;
int x = 10
Which keyword is used to define a block of code that might throw an exception?
throw
finally
catch
try
What is the core principle behind Object-Oriented Programming (OOP) in Java?
Faster execution speed
Improved memory management
Code reusability
Data security
What is the parent class of all exception classes in Java?
Exception
Throwable
RuntimeException
What is the correct syntax to print 'Hello World!' to the console in Java?
print('Hello World!');
System.out.println('Hello World!');
console.log('Hello World!');
echo 'Hello World!';
What is recursion in the context of Java methods?
A method calling itself within its own definition
Calling a method from a different class
Overloading a method with different parameters
Returning multiple values from a method