What is the multilevel inheritance. and also give the Example
of it ?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / 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 ? | 9 Yes | 3 No |
Multilevel inheritance is a java feature where the
properties of a class are inherited by a class which
extends one or more classes which extend its features.
example:
import java.io.*;
class superclass
{
void sum(int x,int y)
{
int add;
add=x+y;
System.out.println("addition="+ add);
}
}
class subclassA extends superclass
{
void subtraction(int a, int b)
{
int sub;
sub=a-b;
System.out.println("subtraction="+sub);
}
}
class subclassB extends subclassA
{
void multiplication(int m, int n)
{
int mult;
mult=m*n;
System.out.println("multipliction="+mult);
}
}
class subclassC extends subclassB
{
public static void main(String arg[])throws IOException;
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
int p,q;
System.out.println("enter value in p");
p=Integer.parseInt(br.readLine());
System.out.println("enter value in q");
q=Integer.parseInt(br.readLine());
subclassC obj=new subclassC();
obj.multiplication(p,q);
obj.subtraction(p,q);
obj.sum(p,q);
}
}
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / punit chauhan
Plz send answer of this question my email -
punitchauhan22@gmail.com
Is This Answer Correct ? | 8 Yes | 4 No |
Answer / guest
a multilevel inheritence is one in which there exist one base
class ,one derived class and multiple intermediate base class.
Is This Answer Correct ? | 6 Yes | 8 No |
What is the Layout for ToolBar?
is JVM platform dependent or independent..?
11 Answers IBM, Tech Mahindra,
What is the difference between an array and an array list?
Can one thread block the other thread?
How destructors are defined in java?
What is boolean logic?
What about interrupt() method of thread class ?
What is a final class ?
what is platform dependent translation and platform dependent programming language
What is split return?
Can you override a private or static method in java?
what is object slice?