Abstract Class Inheriting Concrete Class in Java


Create a Java program to demonstrate the concept of an abstract class inheriting a concrete class

  • There's a Shape class with a method display(), which prints "Shape display".
  • Circle is an abstract class that extends Shape and declares an abstract method draw().
  • SubCircle is a concrete class that extends Circle and provides an implementation for the draw() method.
  • In the Main class, an instance of SubCircle is created.
  • The display() method of Shape is called on the SubCircle instance, which prints "Shape display".
  • Then, the draw() method of SubCircle is called, which prints "Drawing Circle".

Source Code

class Shape
{
	void display()
	{
		System.out.println("Shape display");
	}
}
 
abstract class Circle extends Shape
{
	abstract void draw();
}
 
class SubCircle extends Circle
{
	@Override
	void draw()
	{
		System.out.println("Drawing Circle");
	}
}
 
public class Main
{
	public static void main(String[] args)
	{
		SubCircle circle = new SubCircle();
		circle.display();
		circle.draw();
	}
}

Output

Shape display
Drawing Circle