Java Program to Find Area of Square Using Method Overloading
A square is a simple flat shape in a plane, defined by four points at the four corners. It has four sides with equal length and four corners with right angles.
Method Overloading: 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 square using the method overloading.
Area of the Square
The area of the square is the square of its sides. We can simply calculate the area of the square using the following formula:
Area of the Square: A = a2
Here, a is the side of the square.
Below is the implementation of the above approach:
Showing the method overloading of Area() function which has different parameters of square sides of different data-type( float , int , double)
Area of the Square: 100.0 Area of the Square: 10.240000000000002
Showing method overloading of Area() function which returns the area of different figures like( square, circle, rectangle)
Area of the Circle: 346.36059005827474 Area of the Square: 9.0 Area of the Rectangle: 20
Time complexity: O(1) because it is doing constant operations
Auxiliary space: O(1)