What will the following Java code snippet print to the console?
for (int i = 1; i <= 3; i++) { System.out.print(i + " "); }
1 2 3
The code will result in a compilation error.
123
3 2 1
Can you overload a method in Java by changing only the return type?
No
Yes
What is the base class for all checked exceptions in Java?
Exception
RuntimeException
Error
Throwable
In Java, what is an instance of a class?
A blueprint or template for creating objects
A concrete, realized version of a class
A variable that stores data
A method that performs a specific action
What is the core principle behind Object-Oriented Programming (OOP) in Java?
Data security
Faster execution speed
Improved memory management
Code reusability
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"); }
Greater than 10
x is 5
Less than or equal to 10
Which method is used to remove an element at a specific index from an ArrayList?
delete()
remove()
extract()
discard()
Which access modifier allows a subclass in a different package to access a member of its superclass?
public
default
private
protected
What is the role of parameters in a Java method?
To declare variables within the method.
To provide input values to the method.
To define the method's return type.
To control the method's visibility.
What are fields in a Java class?
Keywords reserved by the Java language
Variables that hold the state of an object
Constructors used to create objects
Methods that belong to the class