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 do you mean by platform independence? What is an interface?
What is preflight request?
Is Java a dying language?
Is java still relevant?
Can we declare the static variables and methods in an abstract class?
What are packages in java?
How to restrict a member of a class from inheriting by its sub classes?
What is package protected in java?
Difference between error and exception
What is the difference between && and & in java?
What is ascii format?
Explain exception chaining in java?
What is anagram of a string?
why not override thread to make a runnable? : Java thread
How do you do descending order in java?