Write a Java program to create an interface Shape with the getArea() method. Create three classes Rectangle, Circle, and Triangle that implement the Shape interface. Implement the getArea() method for each of the three classes.

Source Code:

interface Shape {
double getArea();
}

class Rectangle implements Shape {
double l = 5, w = 4;
public double getArea() {
return l * w;
}
}

class Circle implements Shape {
double r = 3;
public double getArea() {
return 3.14 * r * r;
}
}

class Triangle implements Shape {
double b = 4, h = 5;
public double getArea() {
return 0.5 * b * h;
}
}

public class TestShape {
public static void main(String[] args) {
Shape r = new Rectangle();
Shape c = new Circle();
Shape t = new Triangle();
System.out.println(r.getArea());
System.out.println(c.getArea());
System.out.println(t.getArea());
}
}

Output: