If a method in Java is declared 'private,' where can it be accessed?
Only from within the same class
From any class within the same package
From subclasses, even in different packages
From any class in the application
What is the primary purpose of exception handling in Java?
To completely prevent runtime errors from occurring.
To enforce strict coding standards and prevent compilation errors.
To improve the performance of Java applications.
To provide a mechanism for handling unexpected events during program execution.
Which keyword is used to define a method in Java?
function
define
void
method
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));
IndexOutOfBoundsException
apple
null
banana
What is the purpose of the 'switch' statement in Java?
To check a condition and execute different code blocks based on the result
To define a method
To declare a variable
To execute a block of code repeatedly
What is a potential risk of poorly implemented recursion?
All of the above.
StackOverflowError.
Slower execution speed.
Increased memory usage.
Which keyword is used to exit a loop prematurely in Java?
break
return
exit
continue
What is the default access modifier for a class member in Java if none is specified?
protected
default (package-private)
private
public
What is the core principle behind Object-Oriented Programming (OOP) in Java?
Data security
Improved memory management
Code reusability
Faster execution speed
Which keyword is used to define a block of code that might throw an exception?
try
throw
finally
catch