Question 02 of 05

Constructor

Write a Java program to demonstrate parameterized constructor.

C++
class Rectangle {
    int length, width;
    Rectangle(int l, int w) { length = l; width = w; }
    int area() { return length * width; }
}
public class Main {
    public static void main(String[] args) {
        Rectangle r = new Rectangle(5, 3);
        System.out.println("Area: " + r.area());
    }
}
Question 2 of 5