WorksheetsJava Method Overloading and Recursion Quiz
Total questions: 16
Worksheet time: 8mins
What is method overloading in Java?
Defining multiple methods with the same name but different parameter lists.
Defining multiple methods with the same name and same parameter lists.
Defining methods with different names.
Defining methods that cannot be called.
What happens when an overloaded method is invoked?
Java uses the type and/or number of arguments to determine which version to call.
Java randomly selects a method to call.
Java cannot determine which method to call.
Java throws an error.
What is recursion?
A function that calls itself directly or indirectly.
A function that cannot call itself.
A method that is overloaded.
A method that is static.
What is the significance of the static keyword in Java?
It is used for memory management.
It is used to define instance variables.
It is used to create objects.
It is used to define constructors.
What will happen if a method is declared as final?
It cannot be overridden.
It can be overridden.
It cannot be called.
It can be called multiple times.
What is the purpose of the 'this' keyword in Java?
It is used to define static methods.
It is used to create a new object.
It refers to the parent class.
It refers to the current object instance.
What is the output of the following code: System.out.println(2 * 3 + 4); ?
10
12
6
8
What is the difference between '== ' and 'equals()' in Java?
'==' is used for primitive types, while 'equals()' is used for objects only.
There is no difference; they are interchangeable.
'==' checks for value equality, while 'equals()' checks for reference equality.
'==' checks for reference equality, while 'equals()' checks for value equality.
What is the purpose of the 'super' keyword in Java?
It is used to create an instance of the current class.
It is used to define static variables.
It is used to call the parent class constructor.
It is used to access private methods of the parent class.
What is the difference between a class and an interface in Java?
A class can implement multiple interfaces, but an interface cannot implement a class.
Classes can have method implementations, while interfaces cannot.
Classes can be instantiated, while interfaces cannot.
All of the above.
What is the purpose of the 'final' keyword when applied to a variable in Java?
It makes the variable static.
It prevents the variable from being modified.
It allows the variable to be modified.
It allows the variable to be overridden.
What is the effect of declaring a class as abstract in Java?
It cannot be instantiated.
It can be instantiated but not inherited.
It can be instantiated only once.
It can be instantiated multiple times.
What does the 'static' keyword signify when applied to a method in Java?
It cannot be called from outside the class.
It can be called without creating an instance of the class.
It can only be called from within the same class.
It can be overridden in subclasses.
What is the purpose of the 'abstract' method in an abstract class?
It can be instantiated directly.
It must be implemented by subclasses.
It cannot have any parameters.
It can only be called from within the same class.
What is the role of the 'interface' keyword in Java?
It defines a contract that classes can implement.
It is used to define static methods.
It allows for multiple inheritance of classes.
It is used to create abstract classes.
What does the 'synchronized' keyword do in Java?
It prevents a method from being overridden.
It makes a method static.
It restricts access to a method to one thread at a time.
It allows multiple threads to access a method simultaneously.
