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 ?    14 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is encapsulation?

833


Which is the class in java?

756


Explain enumeration in java?

784


What is java in layman terms?

756


Difference between nested and inner classes ?

824


How do you write a good declaration?

712


What are the restrictions imposed on method overriding?

790


Can we use string in the switch case?

812


How finally used under exception handling?

734


How do you check if a string contains only numeric digits?

884


How do you insert a line break?

704


What is java lang object?

757


How to find the largest value from the given array.

774


Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?

821


What is floor math?

705