//Program to print number of sides for differet shapes
abstract class Shape{
abstract void numberofsides();
}
class Trapezoid extends Shape{
void numberofsides()
{
System.out.println("Number of sides of Trapeziod is : 4");
}
}
class Triangle extends Shape
{
void numberofsides()
{
System.out.println("Number of sides of Triangle is : 3");
}
}
class Hexagon extends Shape
{
void numberofsides()
{
System.out.println("Number of sides of Hexagon is : 6");
}
}
class Sides
{
public static void main(String args[])
{
Shape s;
s=new Trapezoid();
s.numberofsides();
s=new Triangle();
s.numberofsides();
s=new Hexagon();
s.numberofsides();
}
}
Output:
Number of sides of Trapeziod is : 4
Number of sides of Triangle is : 3
Number of sides of Hexagon is : 6
Write a Java program to create an interface named Shape, that contains an empty method named numberOfSides(). Provide three classes named Trapezoid, Triangle and Hexagon, such that each one of the classes contain only the method numberOfSides(), that contains the number of sides in the given geometric figure.