Java MCQs on method overriding in Java Programming Language. 1. Which of this keyword can be used in a subclass to call the constructor of superclass?
Answer: a 2. What is the process of defining a method in a subclass having same name & type signature as a method in its superclass? Answer: b 3. Which of these keywords can be used to prevent Method overriding? Answer: d 4. Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B? Answer: d 5. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”
a) final, native, private Answer: d 6. Which of these is supported by method overriding in Java? Answer: c 7. What will be the output of the following Java program?
a) 2 Answer: c 8. What will be the output of the following Java program?
a) 2 2 Answer: d $ javac inheritance.java Exception in thread "main" java.lang.Error: Unresolved compilation problem: i cannot be resolved or is not a field 9. What will be the output of the following Java program?
a) Compilation error Answer: d 10. What will be the output of the following Java program?
a) 1 Answer: b $ javac Dynamic_dispatch.java $ java Dynamic_dispatch 2 What is the process of defining a method in a subclass having same name and type signature as?When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass overrides the method in the superclass.
What is the process of defining a method in subclass having same name & type parameters as a method in its superclass?If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java.
What is process of defining two or more methods within same class that have same name but different parameters declaration method?If a class has multiple methods having same name but different in parameters, it is known as Method Overloading.
What is the process of defining a method in terms of itself that is a method that calls itself?Recursion is the process of defining something in terms of itself. It allows us to define method that calls itself repeatedly until it meets some base case condition.
|