What is the multilevel inheritance. and also give the Example
of it ?

Answer Posted / namrata

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between null and void?

744


What is Java Shutdown Hook?

855


Explain the selection sort algorithm?

872


Write a program to show whether a graph is a tree or not using adjacency matrix.

867


What are internal variables?

789


What is jar?

871


What are multiple inheritances?

857


What are the two main uses of volatile in Java?

829


Why is java not 100% pure oops?

835


How do you compare arrays in java?

722


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

864


What is the function of static in java?

790


What is a file pointer?

730


Why map is used in java?

816


What is the purpose of using break in each case of switch statement?

798