-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (28 loc) · 745 Bytes
/
Main.java
File metadata and controls
30 lines (28 loc) · 745 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
import java.util.Scanner;
class Shape {
double getArea() {
return 0; // Default
}
}
class Rectangle extends Shape {
double len, wid;
Rectangle(double len, double wid) {
this.len = len;
this.wid = wid;
}
@Override
double getArea() {
return len * wid;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter length of rectangle: ");
double len = sc.nextDouble();
System.out.print("Enter width of rectangle: ");
double wid = sc.nextDouble();
Rectangle rect = new Rectangle(len, wid);
System.out.println("Area of Rectangle: " + rect.getArea());
}
}