Java program to create an interface and implement it in a class.
Below code is used to create an interface and implement it in a class:
import java.io.*;
import java.util.Scanner;
interface Shape
{
final static double pi=3.142;
public void area(float r);
}
class Circle implements Shape
{
float area_circle;
public void area(float r)
{
area_circle=(float)pi*r*r;
System.out.println("area is :"+area_circle);
}
public static void main(String[] args)
throws IOException
{
Circle c=new Circle();
float radius;
Scanner s=new Scanner(System.in);
System.out.println("Enter the radius");
radius=s.nextInt();
c.area(radius);
}
}