-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.java
52 lines (43 loc) · 848 Bytes
/
Shape.java
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
class Shape
{
public double getArea()
{
return 0.0;
}
}
class Circle extends Shape
{
private double radius;
public Circle(double radius)
{
this.radius = radius;
}
public double getArea()
{
return Math.PI * radius * radius;
}
}
class Rectangle extends Shape
{
private double width;
private double height;
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}
public double getArea()
{
return width * height;
}
}
public class Shape1
{
public static void main(String[] args)
{
Circle circle = new Circle(5);
Rectangle rectangle = new Rectangle(4, 6);
System.out.println("Circle Area: " + circle.getArea());
System.out.println("Rectangle Area: " + rectangle.getArea());
}
}