Area of rectangle using default constructor in java

Hey guys!! Welcome to flower brackets blog. In this post we are going to learn area of rectangle using default constructor in java.

Area of rectangle using default constructor in java

Area of rectangle using default constructor in java

A default constructor is one which takes no arguments. Java runtime creates one if a class does not explicitly define any constructors.

Now let’s see java program to calculate area of rectangle using default constructor,

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

Related Posts