Wednesday, October 22, 2025
HomeLanguagesJavaJava Program to Find Area of Rectangle Using Method Overloading

Java Program to Find Area of Rectangle Using Method Overloading

A rectangle is a simple flat figure in a plane. It has four sides and four right-angles. In a rectangle all four sides are not of equal length like a square, sides opposite to each other have equal length and both the diagonals of the rectangle have equal length.

Method overloading allows different methods to have the same name, but different signatures where the signature can differ by the number of input parameters or type of input parameters or both. 

In this article, we will learn how to find the area of the rectangle using the method overloading.

Area of the Rectangle

The area of the rectangle is the product of its length and width/breadth. We can simply calculate the area of the rectangle using the following formula:

Formula:

Area of the rectangle: A = S * T

Here, S is the length of the rectangle and T is the breadth/width of the rectangle.

Below is the implementation of the above approach:

Java




// Java program to find the area of
// the rectangle using Method Overloading
import java.io.*;
 
class Rectangle {
 
    // Overloaded Area() function to
    // calculate the area of the rectangle
    // It takes two double parameters
    void Area(double S, double T)
    {
        System.out.println("Area of the rectangle: "
                           + S * T);
    }
 
    // Overloaded Area() function to
    // calculate the area of the rectangle.
    // It takes two float parameters
    void Area(int S, int T)
    {
        System.out.println("Area of the rectangle: "
                           + S * T);
    }
}
 
class GFG {
 
    // Driver code
    public static void main(String[] args)
    {
 
        // Creating object of Rectangle class
        Rectangle obj = new Rectangle();
 
        // Calling function
        obj.Area(20, 10);
        obj.Area(10.5, 5.5);
    }
}


Output

Area of the rectangle: 200
Area of the rectangle: 57.75

Time Complexity: O(1)

Auxiliary Space: O(1) because constant variables are used

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS