Overriding

 class Plane{

    public void takeOff(){

    System.out.println("plane takeOff");

    }

    public void fly(){

    System.out.println("plane fly");

    }

    public void land(){

    System.out.println("plane land");

    }

}

class CargoPlane extends Plane{

    public void takeOff(){

    System.out.println("CargoPlane takeOff");

    }

    public void fly(){

    System.out.println("CargoPlane fly");

    }

    public void land(){

    System.out.println("CargoPlane land");

    }

}

class PassengerPlane extends Plane{

    public void takeOff(){

    System.out.println("PassengerPlane takeOff");

    }

    public void fly(){

    System.out.println("PassengerPlane fly");

    }

    public void land(){

    System.out.println("PassengerPlane land");

    }

}

class FighterPlane extends Plane{

    public void takeOff(){

    System.out.println("FighterPlane takeOff");

    }

    public void fly(){

    System.out.println("FighterPlane fly");

    }

    public void land(){

    System.out.println("FighterPlane land");

    }

}

public class Main

{

public static void main(String[] args) {

Plane p= new PassengerPlane();

p.takeOff();

p.fly();

p.land();

System.out.println();

Plane c= new CargoPlane();

c.takeOff();

c.fly();

c.land();

System.out.println();

Plane f= new FighterPlane();

f.takeOff();

f.fly();

f.land();

System.out.println();

}

}

----------------------------------------------------------------------------------------------------------------

class Plane{

    public void takeOff(){

    System.out.println("plane takeOff");

    }

    public void fly(){

    System.out.println("plane fly");

    }

    public void land(){

    System.out.println("plane land");

    }

}

class CargoPlane extends Plane{

    public void takeOff(){

    System.out.println("CargoPlane takeOff");

    }

    public void fly(){

    System.out.println("CargoPlane fly");

    }

    public void land(){

    System.out.println("CargoPlane land");

    }

}

class PassengerPlane extends Plane{

    public void takeOff(){

    System.out.println("PassengerPlane takeOff");

    }

    public void fly(){

    System.out.println("PassengerPlane fly");

    }

    public void land(){

    System.out.println("PassengerPlane land");

    }

}

class FighterPlane extends Plane{

    public void takeOff(){

    System.out.println("FighterPlane takeOff");

    }

    public void fly(){

    System.out.println("FighterPlane fly");

    }

    public void land(){

    System.out.println("FighterPlane land");

    }

}

class Airport{

    public void aeroplane(Plane p){

        p.takeOff();

p.fly(); 

p.land();

System.out.println();    

    }

}

public class Main

{

public static void main(String[] args) {

Plane p= new PassengerPlane();

Plane c= new CargoPlane();

Plane f= new FighterPlane();

Airport a = new Airport();

a.aeroplane(p);

a.aeroplane(c);

a.aeroplane(f);

}

}

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.