Java Interview Question Set 11
Categories: Java 8(JDK1.8)
How Many Type of the Inheritance?
There are five types of inheritance in Java.
a) Single-level inheritance
b) Multi-level inheritance
c) Multiple Inheritance
d) Hierarchical Inheritance
e) Hybrid Inheritance
f) Multiple inheritance is not supported in Java through class.
Why is Inheritance used in Java?
There are various advantages of using inheritance in Java that is given below.
a) Inheritance provides code reusability. The derived class does not need to redefine the method of base class unless it needs to provide the specific implementation of the method.
b) Runtime polymorphism cannot be achieved without using inheritance.
c) We can simulate the inheritance of classes with the real-time objects which makes OOPs more realistic.
d) Inheritance provides data hiding. The base class can hide some data from the derived class by making it private.
e) Method overriding cannot be achieved without inheritance. By method overriding, we can give a specific implementation of some basic method contained by the base class.
Which class is the superclass for all the classes?
The object class is the superclass of all other classes in Java.
Why is multiple inheritance not supported in java?
To reduce the complexity and simplify the language, multiple inheritance is not supported in java. Consider a scenario where A, B, and C are three classes. The C class inherits A and B classes. If A and B classes have the same method and you call it from child class object, there will be ambiguity to call the method of A or B class.