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
Post a Comment