Thursday 17 March 2016

How to create multi level inheritance in java

2.Multi level Inheritance:-
When more than two classes we use extends from one to another in a chain process.


class Mobile

{

public void nokia()

{

System.out.println("Phone is ringing");
}
}
class Laptop extends Mobile
{
public void acer()
{
System.out.println("Beautiful laptop");
}
}
public class Main extends Laptop
{
public void connect()
{
System.out.println("It connects the both classes");
}
public static void main(String args[])
{
Main m = new Main();
m.nokia();
m.acer();
m.connect();
}
}

OUTPUT:-
C:\Users\Satyendra\Desktop>javac Main.java
C:\Users\Satyendra\Desktop>java Main
Phone is ringing
Beautiful laptop
It connects the both classes

No comments:

Post a Comment