Study and learn Interview MCQ Questions and Answers on Inheritance in Java. You can know about Multilevel and Multiple Inheritances. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.
Go through Java Theory Notes on Inheritance before reading these objective questions.
Variables and Methods are reused through inheritance. Constants are nothing but variables only if they hold some value.
Superclass or Super-Class
Subclass
Multi-Level Inheritance is somewhat complicated.
Yes. One simple example is ANIMAL Superclass and HORSE Subclass. HORSE is-a/is-an ANIMAL.
Java supports extending from only one Superclass. Multilevel inheritance is completely supported by Java. Whereas Multiple and Hybrid inheritances are based on Multiple-Superlclasses scenario and hence not supported by Java.
True.
True
Yes. The last class inherits all of the properties and methods of all of the classes above it in the chain.
Multiple Inheritance
Yes, true.
Yes. True. A Constructor is class-specific. It is not like a method that can be shared.
class B { void show(){} } class A { void hide(){} }
As there is no use of the "extends" keyword, inheritance does not come into the picture. So, there is no superclass or subclass present in the above example.
class Liquid { void pour(){} } class Juice extends Liquid { void filter(){} }
As the Juice class is extending from the Liquid class, Juice is a subclass and Liquid is a superclass. Simply put, the class before the "extends" keyword is always a Subclass.
The keyword "extends" tells the compiler that the class on the left side is subclassing the class on the right side.
class Sweet { void price() { System.out.print("Sweet=$10 "); } } class Sugar extends Sweet { void price() { super.price(); System.out.print("Sugar=$20"); } } public class JavaInheritance1 { public static void main(String[] args) { Sugar su = new Sugar(); su.price(); } }
Notice the use of the keyword "super". Using this keyword, you can call superclass's methods and variables.
No. Abstract classes and Interfaces do not define a class completely. So, it is not called a full-fledged inheritance of using those.
Access modifiers like default (not a keyword), public, protected and private changed the visibility of a method, variable or a class. Even the keyword "package" also allows grouping of classes and control inheritance levels to some extent.
You can not subclass a class that is marked FINAL.
final class CLASS_NAME //Can not subclass { } class SUBCLASS extends CLASS_NAME //ERROR { }