This section of our 1000+ Java MCQs focuses 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 Sanfoundry Global Education & Learning Series – Java Programming Language. Next Steps:
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn. Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. When a method in a subclass has the same name and type as method in superclass it is known as?Answer: When methods in the superclass and subclass have the same name and signature is called Overridden methods.
Can a subclass have a method with the same name and the same signature as its superclass?If your subclass defines a method with the same name and signature as a method in its superclass, the method in the subclass overrides the one in the superclass. Thus, the subclass does not inherit the method from its superclass.
Which of the following is the process of defining a method in subclass having same name and signature as a method in its super class?Method overriding is when a subclass redefines a method of its superclass, of course the redefined method (of the subclass) has the same name and the same parameter types of the method of its superclass.
When a method has same signature in the base class?If a method in a derived class has the same method signature as its base class's method, it's referred to as an overridden method. Overridden methods are discussed along with polymorphism in chapter 6.
|