Write a Java program to demonstrate method overriding with a subclass that overrides a method from an abstract class
The code defines an abstract class Shape with an abstract method draw, and a concrete subclass Circle that extends the Shape class by providing an implementation for the draw method. In the Main class, you create an instance of the Circle class and invoke the draw method to print "Drawing a circle" to the console. Here's an explanation of the code:
abstract class Shape { abstract void draw(); } class Circle extends Shape { @Override void draw() { System.out.println("Drawing a circle"); } } public class Main { public static void main(String[] args) { Circle circle = new Circle(); circle.draw(); } }
Drawing a circle
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions