Calculate area of rectangle using default constructor in java

Let’s learn to calculate area of rectangle using default constructor in java.

Calculate area of rectangle using default constructor in java

Default constructor is a constructor created by compiler if user does not create a constructor in a class.

calculate area of rectangle using default constructor in java

Now let’s see calculate area of rectangle using default constructor in java.

Also read – java program to find area of rectangle using parameterized constructor

import java.util.*;
class RectangleShape 
{
   int area, length, breadth; 
   RectangleShape() 
   { 
      length = 50; 
      breadth = 20; 
   } 
   void getArea() 
   { 
      area = length * breadth; 
      System.out.println("Area of Rectangle : " + area); 
   }  
}
public class RectangleAreaConstructor
{
   public static void main(String[] args) 
   {
      RectangleShape rs = new RectangleShape(); 
      rs.getArea();
   }
}


Output:

Area of Rectangle : 1000


Also read – wap to find area of rectangle using parameterized constructor in java

Also read – area of rectangle in java

Also read – java program to calculate area and perimeter of rectangle