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 |
how can i connect to database in a applet ?
how to create daemon thread in java?
What is the difference between super class & sub class?
Why java is said to be pass-by-value ?
What is this () in java?
what models are available for event handling?
What is externalizable interface?
What is type inference in java8?
What is a boolean in java?
What is the primary benefit of encapsulation?
What is outofmemoryerror in java?
What is meant by polymorphism?