| 1 | // Program to demonstrate the use of constructors in Java - |
| 2 | class Area { |
| 3 | int length, breadth; |
| 4 | // Parameterized constructor |
| 5 | Area(int m, int n) { |
| 6 | length = m; |
| 7 | breadth = n; |
| 8 | } |
| 9 | // Function to calculate area of rectangle |
| 10 | void rectArea(Area a) { |
| 11 | System.out.println("Length = " + a.length); // Printing length |
| 12 | System.out.println("Breadth = " + a.breadth); // Printing breadth |
| 13 | int area = a.length * a.breadth; // Calculating area |
| 14 | System.out.println("Area of rectangle is: " + area); // Printing area |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | public class constructors { |
| 19 | public static void main(String[] args) { |
nothing calls this directly
no outgoing calls
no test coverage detected