-
Notifications
You must be signed in to change notification settings - Fork 0
/
oops.java
69 lines (64 loc) · 1.45 KB
/
oops.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Shape
{
private String color;
public Shape(String color)
{
this.color = color;
}
public void setColor(String color)
{
this.color = color;
}
public String getColor()
{
return color;
}
public double getArea()
{
return 0.0;
}
}
class Circle extends Shape
{
private double radius;
public Circle(String color, double radius)
{
super(color);
this.radius = radius;
}
@Override
public double getArea()
{
return Math.PI * radius * radius;
}
}
class Rectangle extends Shape
{
private double length;
private double width;
public Rectangle(String color, double length, double width)
{
super(color);
this.length = length;
this.width = width;
}
@Override
public double getArea()
{
return length * width;
}
}
public class oops
{
public static void main(String[] args)
{
Circle circle = new Circle("Red", 5.0);
Rectangle rectangle = new Rectangle("Blue", 4.0, 6.0);
System.out.println("Circle Area: " + circle.getArea());
System.out.println("Circle Color: " + circle.getColor());
System.out.println("Rectangle Area: " + rectangle.getArea());
System.out.println("Rectangle Color: " + rectangle.getColor());
circle.setColor("Green");
System.out.println("New Circle Color: " + circle.getColor());
}
}