0% found this document useful (0 votes)
11 views4 pages

Abstract

The document defines an interface 'shape' with a method 'printarea' and implements it in three classes: 'rectangle', 'triangle', and 'circle'. Each class calculates and prints the area based on user input for dimensions specific to each shape. The main class 'Abstact' creates instances of each shape and calls their respective 'printarea' methods to demonstrate functionality.

Uploaded by

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

Abstract

The document defines an interface 'shape' with a method 'printarea' and implements it in three classes: 'rectangle', 'triangle', and 'circle'. Each class calculates and prints the area based on user input for dimensions specific to each shape. The main class 'Abstact' creates instances of each shape and calls their respective 'printarea' methods to demonstrate functionality.

Uploaded by

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

INTERFACE

import [Link].*;
interface shape
{
public void printarea();
}
class rectangle implements shape
{
public int area_rect;
int a,b;
public void printarea()
{
Scanner s=new Scanner([Link]);
[Link]("enter the length and breadth of rectangle");
a=[Link]();
b=[Link]();
area_rect=a*b;
[Link]("Length of rectangle "+a +"breadth of rectangle "+b);
[Link]("The area ofrectangle is:"+area_rect);
}
}
class triangle implements shape
{
double area_tri;
int a,b;
public void printarea()
{
Scanner s=new Scanner([Link]);
[Link]("enter the base and height of triangle");
a=[Link]();
b=[Link]();
[Link]("Base of triangle "+a +"height of triangle "+b);
area_tri=(0.5*a*b);
[Link]("The area of triangle is:"+area_tri);
}
}
class circle implements shape
{
double area_circle;
int a,b;
public void printarea()
{
Scanner s=new Scanner([Link]);
[Link]("enter the radius of circle");
a=[Link]();
area_circle=(3.14*a*a);
[Link]("Radius of circle"+a);
[Link]("The area of circle is:"+area_circle);
}
}
public class Abstact
{
public static void main(String[] args)
{
rectangle r=new rectangle();
[Link]();
triangle t=new triangle();
[Link]();
circle r1=new circle();
[Link]();
}
}
INTERFACE

You might also like