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

What does the ‘static’ keyword mean? Is it possible to override private or static method in java?

574


What is meant by method?

585


Can we define private and protected modifiers for variables in interfaces?

592


What is the difference between keyword and identifier?

549


What is externalizable?

624






What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?

698


What is the difference between reader/writer and inputstream/output stream?

567


What is the difference between exception and error in java?

502


Is null a string?

562


Is ++ operator is thread safe in java?

525


Give any two differences between C++ and java.

567


If you do not want your class to be inherited by any other class. What would you do?

570


What are drawbacks of singleton class?

533


What is the difference between heap memory and stack memory?

624


What is the difference between the prefix and postfix forms of the ++ operator?

567