What are method parameters used for?
To pass data into a method
To declare variables within a method
To define the method's return type
To control the method's access level
What is the correct syntax to print 'Hello World!' to the console in Java?
print('Hello World!');
System.out.println('Hello World!');
echo 'Hello World!';
console.log('Hello World!');
Which keyword is used to explicitly throw an exception in Java?
try
throw
catch
finally
Why is method overloading useful?
To improve code readability
All of the above
To enhance code flexibility
To avoid code repetition
What is the base class for all checked exceptions in Java?
Exception
RuntimeException
Throwable
Error
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.
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
123
3 2 1
The code will result in a compilation error.
Which access modifier allows a subclass in a different package to access a member of its superclass?
public
private
protected
default
What are fields in a Java class?
Variables that hold the state of an object
Keywords reserved by the Java language
Constructors used to create objects
Methods that belong to the class
What is the result of the expression '10 % 3' in Java?
3
3.33
1
0