Thursday, 6 March 2014

java program on Abstract class named triagle,hexagon



java program on Abstract class named triagle,hexagon


Save as AbstractDemo.java
abstract class shape
{
    void numberofsides()
{
   System.out.println("This is for abstract class");
}
}
class Trapezoid extends shape
{
   void numberofsides()
{
System.out.println("It is having 4 sides");
}
}
class Triangle extends shape
{
 void numberofsides()
{
System.out.println("it is having 3 sides");
}
}
class Hexagonal extends shape
{
 void numberofsides()
{
System.out.println("it is having 6 sides");
}
}
class AbstractDemo
{
public static void main(String args[])
{
  Trapezoid tz=new Trapezoid();
Triangle t=new Triangle();
Hexagonal h=new Hexagonal();
tz.numberofsides();
t.numberofsides();
h.numberofsides();
}
}

No comments: