Polymorphism in Java

 Polymorphism in Java




PROGRAM:

class Shapes
{
    public void color()
    {
        System.out.println("Shapes poccess different color");
    }
}
class Rectangle extends Shapes{

    public void color()
    {
        System.out.println("The color Rectangle is Blue");
    }

}
class Square extends Shapes{

    public void color()
    {
        System.out.println("The color of Square is Red");
    }

}
public class Polymorphism
{
    public static void main(String args[])
    {
        Square s1=new Square();
        s1.color();

        Rectangle r1=new Rectangle();
        r1.color();
    }
}

/*
OUTPUT

The color of Square is Red
The color Rectangle is Blue

*/

Comments

Popular posts from this blog

PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION

PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY

TELEPHONE BOOK USING HASHMAP