-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstract Learn
76 lines (60 loc) · 1.29 KB
/
Abstract Learn
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package AbstractClass2;
public class Circle extends Shape{
Circle(double a)
{
super(a,a);
}
void area()
{
double result=3.1416*a*a;
System.out.println("Result is: "+result);
}
}
package AbstractClass2;
public class Rectangle extends Shape{
Rectangle(double a, double b)
{
super(a,b);
}
@Override
void area() {
double result=a*b;
System.out.println("Result is: "+result);
}
}
package AbstractClass2;
public abstract class Shape {
double a,b;
Shape(double a, double b)
{
this.a=a;
this.b=b;
}
abstract void area();
}
package AbstractClass2;
public class Triangle extends Shape {
Triangle(double a, double b)
{
super(a,b);
}
@Override
void area() {
double result= .5*a*b;
System.out.println("Result is: "+result);
}
}
package AbstractClass2;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
Shape shape;
shape =new Triangle(sc.nextDouble(),sc.nextDouble());
shape.area();
shape =new Rectangle(sc.nextDouble(),sc.nextDouble());
shape.area();
shape =new Circle(sc.nextDouble());
shape.area();
}
}