abstract class abstract method with imlemntiom code example

Example 1: abstract class in java

public abstract class GraphicObject {

   abstract void draw();
}

Example 2: how panache handles abstract class in java

//interface declaration
interface Polygon_Shape {
    void calculateArea(int length, int breadth);
}
 
//implement the interface
class Rectangle implements Polygon_Shape {
    //implement the interface method
    public void calculateArea(int length, int breadth) {
        System.out.println("The area of the rectangle is " + (length * breadth));
    }
}
 
class Main {
    public static void main(String[] args) {
        Rectangle rect = new Rectangle();       //declare a class object
        rect.calculateArea(10, 20);             //call the method
    }
}

Tags:

Misc Example