Interface Implementation in Abstract Class in Java


Write a Java program to demonstrate an abstract class implementing an interface

  • Drawable is an interface with a method draw().
  • Shape is an abstract class that implements the Drawable interface. It provides a concrete implementation of the draw() method and declares an abstract method info().
  • Circle is a subclass of Shape and provides an implementation for the info() method.
  • In the Main class, an instance of Circle is created, and both the draw() and info() methods are called on it. Since Circle inherits the draw() method from Shape, it prints "Drawing shape" when draw() is called. Additionally, Circle provides its own implementation of the info() method, printing "This is a circle" when info() is called.

Source Code

interface Drawable
{
	void draw();
}
 
abstract class Shape implements Drawable
{
	@Override
	public void draw()
	{
		System.out.println("Drawing shape");
	}
 
	abstract void info();
}
 
class Circle extends Shape
{
	@Override
	void info()
	{
		System.out.println("This is a circle");
	}
}
 
public class Main
{
	public static void main(String[] args)
	{
		Circle circle = new Circle();
		circle.draw();
		circle.info();
	}
}

Output

Drawing shape
This is a circle