0% found this document useful (0 votes)
15 views2 pages

PGM 6

Uploaded by

happy worker
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)
15 views2 pages

PGM 6

Uploaded by

happy worker
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
You are on page 1/ 2

abstract class Shape

int a;

abstract void calculateArea();

abstract void calculatePerimeter();

class Circle extends Shape

Circle()

a=0;

Circle(int r)

a=r ;

void calculateArea()

double area=3.14*a*a;

System.out.println("Area of Circle is " + area);

void calculatePerimeter()

double p=2*3.14*a;

System.out.println("Perimeter of Circle is "+p);

}}

class Triangle extends Shape

int b,c;

Triangle()

{
a=b=c=0;

Triangle(int a,int b, int c)

this.a=a;

this.b=b;

this.c=c;

void calculateArea()

double s=(a+b+c)/2.0;

double area=Math.sqrt(s*(s-a)(s-b)(s-c));

System.out.println("Area of Triangle is " + area);

void calculatePerimeter()

double p=a+b+c;

System.out.println("Perimeter of Triangle is "+p);

}}

class AbsShapeDemo

public static void main(String s[])

Circle c1= new Circle(5);

Triangle t1=new Triangle(2,3,4);

c1.calculateArea();

c1.calculatePerimeter();

t1.calculateArea();

t1.calculatePerimeter();

You might also like