-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_Task.java
More file actions
36 lines (35 loc) · 890 Bytes
/
Copy pathlab_Task.java
File metadata and controls
36 lines (35 loc) · 890 Bytes
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
abstract class Shape {
abstract double area();
void display() {
System.out.println("This is a shape");
}
}
class Circle extends Shape {
double radius;
Circle(double radius) {
this.radius = radius;
}
double area() {
return Math.PI * radius * radius;
}
}
class Rectangle extends Shape {
double length, width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
double area() {
return length * width;
}
}
public class lab_Task{
public static void main(String[] args) {
Shape s1 = new Circle(5);
Shape s2 = new Rectangle(4, 6);
s1.display();
System.out.println("Circle Area: " + s1.area());
s2.display();
System.out.println("Rectangle Area: " + s2.area());
}
}