SEP -JAVA

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

 
   
 
 7.Program to demonstrate interface in java program.
 
 
  
interface Shape {
    double calculateArea(); // Abstract method
}

 
class Circle implements Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double calculateArea() {
        return Math.PI * radius * radius;
    }
}
 
public class InterfaceDemo {
    public static void main(String[] args) {
        Circle circle = new Circle(5); // Create a Circle object
        System.out.println("Area of the circle: " + circle.calculateArea()); // Call the method from the interface
    }
}