Solved programming problem

Basic Inheritance Problem 6 in Java.

Source code

Main Class:

package pkg3.c;

public class Bird extends Animal

{

    Bird()

    {

        System.out.println("Bird Created");

    }

    @Override

    void fly()

    {

        System.out.println("Birds Fly");

    }

   

    public static void main(String[] args)

    {

        Animal a = new Bird();

        a.fly();

        a.eat();

    }

}

 

Animal Class:

 

 

package pkg3.c;

 

 

public class Animal 

{

    Animal()

    {

        System.out.println("Animal Created");

    }

    void eat()

    {

        System.out.println("Animal Eats");

    }

    void fly()

    {

        System.out.println("Animal Fly");

    }

}

Output

 

Animal Created

Bird Created

Birds Fly

Animal Eats

Join the discussion

Add your comment