0% found this document useful (0 votes)
0 views

Se

The document defines an abstract class 'Shape' with a method 'Area' and three subclasses: 'Circle', 'Rectangle', and 'Triangle', each implementing the 'Area' method to calculate their respective areas. The 'Main' class demonstrates the use of these shapes by creating instances of each and calling their area methods. The program outputs the area of a circle, rectangle, and triangle based on the provided dimensions.

Uploaded by

talhatariq1979
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)
0 views

Se

The document defines an abstract class 'Shape' with a method 'Area' and three subclasses: 'Circle', 'Rectangle', and 'Triangle', each implementing the 'Area' method to calculate their respective areas. The 'Main' class demonstrates the use of these shapes by creating instances of each and calling their area methods. The program outputs the area of a circle, rectangle, and triangle based on the provided dimensions.

Uploaded by

talhatariq1979
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/ 1

AREA

abstract class Shape {

public Shape() {

System.out.println("parent class constructor") }

abstract void Area(); }

class Circle extends Shape {

private double pie, radius;

public Circle() { pie = 3.14d; radius = 0; }

public Circle(double p, double r) { pie = p; radius = r; }

public void Area() { System.out.println("Circle Area is: " + (pie * radius * radius)); }

class Rectangle extends Shape {

private double length, width;

public Rectangle() { length = 0d; width = 0d; }

public Rectangle(double l, double w) { length = l; width = w; }

public void Area() { System.out.println("Rectangle Area is: " + (length * width)); }

class Triangle extends Shape { private double base, height;

public Triangle() { base = 0d; height = 0d; }

public Triangle(double l, double h) { base = l; height = h; }

public void Area() { System.out.println("Triangle Area is: " + (0.5 * base * height)); }

public class Main { public static void main(String[] args) {

Shape obj = new Circle(3.14d, 5.4d);

Shape obj2 = new Rectangle(2d, 3d);

Shape obj3 = new Triangle(1, 2);

obj.Area(); obj2.Area(); obj3.Area(); }

You might also like