Cycle 02
Lab Cycle 2 — OOP Concepts
Constructor
Problem Statement
Write a Java program to demonstrate parameterized constructor.
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