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
What happens if I remove static from main method?
How will you serialize a singleton class without violating singleton pattern?
How can we make string upper case or lower case?
What is the definition of tree ?
Which package has light weight components in java programming?
How can you share data between two thread in Java?
Explain the term virtual machine?
How many types of literals are there in JAVA?
What is a class instance variable?
How can we find the sum of two linked lists using stack in java?
Can you write a java class that could be used both as an applet as well as an application?
Explain a situation where finally block will not be executed?
What is the disadvantage of synchronization?
Is java a digit method?
What is thread safe java?