Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Shape {
- public double getArea() {
- // Default implementation for the base class, return 0.
- return 0;
- }
- }
- class Rectangle extends Shape {
- private double length;
- private double width;
- public Rectangle(double length, double width) {
- this.length = length;
- this.width = width;
- }
- @Override
- public double getArea() {
- return length * width; // Calculate the area of the rectangle
- }
- }
- public class Main {
- public static void main(String[] args) {
- Rectangle rectangle = new Rectangle(5.0, 3.0);
- System.out.println("Area of the rectangle: " + rectangle.getArea());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement