Example 1 : Program that illustrates how to use abstract class in java using class shape
abstract class Shape
{
void display()
{
}
}
class Circle extends Shape
{
void display()
{
System.out.println("You are using circle class");
}
}
class Rectangle extends Shape
{
void display()
{
System.out.println("You are using rectangle class");
}
}
class Triangle extends Shape
{
void display()
{
System.out.println("You are using triangle class");
}
}
class AbstractClassDemo
{
public static void main(String args[])
{
Shape sObj = new Circle();
sobj.display();
sObj = new Rectangle();
sobj.display();
sObj = new Triangle();
sobj.display();
}
}
Output
You are using circle class
You are using rectangle class
You are using triangle class