Untitled

 avatar
user_9763778
plain_text
7 months ago
831 B
5
Indexable
Never
abstract class Shape{
        public abstract void numOfSides();
}
class Rectangle extends Shape{
        public void numOfSides(){
                System.out.println("No. Of Sides of rectangle: 4");
        }
}
class Triangle extends Shape{
        public void numOfSides(){
                System.out.println("No. Of Sides of triangle: 3");
        }
}
class Hexagon extends Shape{
        public void numOfSides(){
                System.out.println("No. Of Sides of hexagon: 6");
        }
}
public class Polymorphism{
        public static void main(String [] args){
                Rectangle r = new Rectangle();
                Triangle t = new Triangle();
                Hexagon h = new Hexagon();
                r.numOfSides();
                t.numOfSides();
                h.numOfSides();
                
        }
}
Leave a Comment