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
Can a boolean be null java?
Write a program to reverse array in place?
how to prepare for IT Officers Interview in Banks
When is the arraystoreexception thrown?
What are the differences between getting and load method?
Can we have multiple public classes in a java source file?
How an object is serialized in java?
What is pre increment and post increment in java?
How many static init can you have?
Is java 1.7 the same as java 7?
What is the purpose of using the java bean?
does java support pointers?
What is the applet security manager, and what does it provide?
What are different ways of object creation in java ?
Can I declare a class as private?