WorksheetsJava Programming Concepts Quiz
Total questions: 18
Worksheet time: 9mins
What is method overloading in Java?
Using different method names for the same functionality
Using the same method name with different return types
Using the same method name in different classes
Using the same method name with different parameter types or counts
Which keyword is used to prevent a class from being extended?
private
protected
final
static
What does the 'super' keyword do in Java?
It overrides a method
It defines a static method
It accesses superclass members
It creates a new instance of a class
What is the output of the following code: 'System.out.println(10 + 20);'?
10
20
30
40
What is recursion in programming?
A method that cannot return a value
A method that is called by the main method
A method that calls another method
A method that calls itself
Which of the following is NOT a valid access modifier in Java?
private
public
internal
protected
What is the purpose of the 'final' keyword when applied to a variable?
It allows the variable to be changed
It prevents the variable from being modified
It makes the variable static
It makes the variable accessible only within its class
In Java, what is a nested class?
A class that is defined within another class
A class that extends another class
A class that implements an interface
A class that cannot be instantiated
What is the output of the following code: 'System.out.println(Math.pow(2, 3));'?
10
9
8
6
Which of the following statements about static methods is true?
They can only be called from within the same class
They can be called without creating an instance of the class
They can access instance variables directly
They can access non-static methods
What is the main advantage of method overriding?
It allows a subclass to provide a specific implementation of a method
It prevents a method from being inherited
It allows multiple methods to have the same name
It makes the code more complex
What is the purpose of the parse methods in Java?
To convert strings to other data types
To format output data
To parse JSON data
To read input from the console
Which of the following is a characteristic of a static nested class?
It can be instantiated without an outer class instance
It cannot access static members of the outer class
It requires an instance of the outer class to be created
It can access instance variables of the outer class
What happens if a recursive method does not have a base condition?
It will return a null value
It will cause a stack overflow error
It will terminate immediately
It will execute successfully
What is the output of the following code: 'System.out.println(5 * 5);'?
30
10
15
25
Which of the following statements about inheritance is true?
Inheritance is not supported in Java
A subclass can inherit from multiple superclasses
A superclass cannot be inherited
A subclass can override methods of its superclass
What is the purpose of the 'protected' access modifier?
It allows access from anywhere
It allows access within the same package and subclasses
It restricts access to the class only
It allows access only within the same class
What is the output of the following code: 'System.out.println(10 / 2);'?
20
2
5
10
