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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.