Abstract Class and its Implementation

Aim: 
To Write a Java program to create an abstract class named Shape that contains an empty method named number Of Sides ( ).Provide three classes named Trapezoid, Triangle and Hexagon such that each one of the classes extends the class Shape. Each one of the classes contains only the method number Of Sides ( ) that shows the number of sides in the given geometrical figures.

Description:
A method without method body is called abstract method. A class thatcontains abstract method is called abstract class. It is possible to implement the abstract methods differently in the subclasses of an abstract class. These different implementations will help the programmer to perform different tasks depending on the need of the sub classes. Moreover, the common members of the abstract class are also shared by the sub classes.

Program:
import java.lang.*;
abstract class Shape
{
abstract void numberOfSides();
}
class Traingle extends Shape
{
public void numberOfSides()
{ System.out.println("three");
}
}
class Trapezoid extends Shape
{ public void numberOfSides()
{ System.out.println("four");
}
}
class Hexagon extends Shape
{ public void numberOfSides()
{ System.out.println("six");
}
}
public class Sides
{
public static void main(String arg[])
{ Traingle T=new Traingle();
Trapezoid Ta=new Trapezoid();
Hexagon H=new Hexagon();
T.numberOfSides();
Ta.numberOfSides();
H.numberOfSides();
}
}