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

Abstract

The document contains a Java program that defines an abstract class 'Shape' and three subclasses: 'Rectangle', 'Triangle', and 'Cricle'. Each subclass implements the 'printArea' method to calculate and display the area based on user input. The main method creates instances of each shape and calls their respective area calculation methods.

Uploaded by

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

Abstract

The document contains a Java program that defines an abstract class 'Shape' and three subclasses: 'Rectangle', 'Triangle', and 'Cricle'. Each subclass implements the 'printArea' method to calculate and display the area based on user input. The main method creates instances of each shape and calls their respective area calculation methods.

Uploaded by

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

import java.util.

*;
abstract class Shape {
int length, breadth, radius;
Scanner input = new Scanner(System.in);
abstract void printArea();
}
class Rectangle extends Shape {
void printArea() {
System.out.println("*** Finding the Area of Rectangle ***");
System.out.print("Enter length and breadth: ");
length = input.nextInt();
breadth = input.nextInt();
System.out.println("The area of Rectangle is: " + length * breadth);
}
}
class Triangle extends Shape {
void printArea() {
System.out.println("\n*** Finding the Area of Triangle ***");
System.out.print("Enter Base And Height: ");
length = input.nextInt();
breadth = input.nextInt();
System.out.println("The area of Rectangle is: " + (length * breadth) / 2);
}
}
class Cricle extends Shape {
void printArea() {
System.out.println("\n*** Finding the Area of Cricle ***");
System.out.print("Enter Radius: ");
radius = input.nextInt();
System.out.println("The area of Rectangle is: " + 3.14f * radius * radius);
}
}
public class Abstract {
public static void main(String[] args) {
Rectangle rec = new Rectangle();
rec.printArea();
Triangle tri = new Triangle();
tri.printArea();
Cricle cri = new Cricle();
cri.printArea();
}
}

You might also like