-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract_class.java
More file actions
43 lines (42 loc) · 1.22 KB
/
Copy pathAbstract_class.java
File metadata and controls
43 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
abstract class Shape{
static int a , b;
abstract int printArea();
}
class Rectangle extends Shape{
int printArea(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the length and breadth of a rectangle");
super.a = sc.nextInt();
super.b = sc.nextInt();
return (a*b);
}
}
class Circle extends Shape{
int printArea(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the radius of a circle: ");
super.a = sc.nextInt();
return (int) (3.14*a*a);
}
}
class Triangle extends Shape{
int printArea(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the base and height of a triangle: ");
super.a = sc.nextInt();
super.b = sc.nextInt();
return (int)(0.5*a*b);
}
}
class Abstract_class {
public static void main(String [] args){
Shape o;
o = new Rectangle();
System.out.println("Area: "+ o.printArea());
o = new Circle();
System.out.println("Area: "+ o.printArea());
o = new Triangle();
System.out.println("Area: "+ o.printArea());
}
}