0% found this document useful (0 votes)
8 views1 page

Area Calculation with Java Interfaces

The document presents a Java program that calculates the area of a rectangle and a circle using interfaces. It defines an interface 'Shape' with a method 'calculateArea', and implements this interface in two classes: 'Rectangle' and 'Circle'. The main method creates instances of both shapes and prints their respective areas.

Uploaded by

shambhupawar293
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Area Calculation with Java Interfaces

The document presents a Java program that calculates the area of a rectangle and a circle using interfaces. It defines an interface 'Shape' with a method 'calculateArea', and implements this interface in two classes: 'Rectangle' and 'Circle'. The main method creates instances of both shapes and prints their respective areas.

Uploaded by

shambhupawar293
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

5. Develop a program to find area of rectangle and circle using interfaces.

public class aofrect {

interface Shape{

double calculateArea();

static class Rectangle implements Shape{

private double width;

private double height;

public Rectangle(double width, double height){

[Link] = width;

[Link] = height;

@Override

public double calculateArea(){

return width*height;

static class Circle implements Shape{

private double radius;

public Circle(double radius){

[Link] = radius;

@Override

public double calculateArea(){

return [Link]*radius*radius;

public static void main(String args[]){

Shape rectangle = new Rectangle(5.0,3.0);

Shape circle = new Circle(2.5);

[Link]("Rectangle Area:"+[Link]());

[Link]("Circle Area:"+[Link]());

OUTPUT

You might also like