What is the multilevel inheritance. and also give the Example
of it ?

Answer Posted / fatima deshmukh

Multilevel inheritance is a java feature where the
properties of a class are inherited by a class which extends
one class and which extend its features...

Example:

public class A {
public String getName(){
return "Fatima";
}
}

public class B extends A {
public int getAge() {
return 25;
}
}

public class C extends B {
public String getAddress(){
return "Panvel,Navi Mumbai India";
}
}

public class D extends C {
public void print {
System.out.println(getName());
System.out.println(getAge());
System.out.println(getAddress());
}
}

This method would print the following in the console:
Fatima
25
Panvel, Navi Mumbai, India

Here in class D you are calling methods that are available
inside classes A, B & C. Though D extends only class C, it
would in turn inherit the properties of the classes extended
by C and its parents.

This is multi level inheritance.

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how are methods defined?

791


What is type parameter in java?

719


Why deletion in linkedlist is fast than arraylist?

771


When we should use serialization?

797


What is polymorphism java example?

764


How is string immutable in java?

780


Is the milky way in a void?

751


Differentiate between a class and an object.

802


What is qms certification?

718


Why is String immutable?

836


What is the replace tool?

772


How to write custom exception in java?

816


Explain polymorphism citing an example.

805


Is arraylist zero based?

775


Is string a datatype?

740