Abstract Class Method Interactions in Java


Create a Java program to demonstrate a method in an abstract class calling an abstract method

  • There's an abstract class Shape with an abstract method draw() and a concrete method display() which calls draw().
  • Circle is a concrete class that extends Shape and provides an implementation for the draw() method.
  • In the Main class, an instance of Circle is created.
  • The display() method of Circle is called, which first prints "Displaying shape...", then calls the draw() method of Circle, which prints "Drawing circle".

Source Code

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

Output

Displaying shape...
Drawing circle