Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Java/Program.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class JavaExample
{
void calculateArea(float x)
{
System.out.println("Area of the square: "+x*x+" sq units");
}
void calculateArea(float x, float y)
{
System.out.println("Area of the rectangle: "+x*y+" sq units");
}
void calculateArea(double r)
{
double area = 3.14*r*r;
System.out.println("Area of the circle: "+area+" sq units");
}
public static void main(String args[]){
JavaExample obj = new JavaExample();

/* This statement will call the first area() method
* because we are passing only one argument with
* the "f" suffix. f is used to denote the float numbers
*
*/
obj.calculateArea(6.1f);

/* This will call the second method because we are passing
* two arguments and only second method has two arguments
*/
obj.calculateArea(10,22);

/* This will call the second method because we have not suffixed
* the value with "f" when we do not suffix a float value with f
* then it is considered as type double.
*/
obj.calculateArea(6.1);
}
}
16 changes: 16 additions & 0 deletions Java/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Method Overloading in Java with examples
| FILED UNDER: OOPS CONCEPT

Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different. It is similar to constructor overloading in Java, that allows a class to have more than one constructor having different argument lists.

let’s get back to the point, when I say argument list it means the parameters that a method has: For example the argument list of a method add(int a, int b) having two parameters is different from the argument list of the method add(int a, int b, int c) having three parameters.


QUESTION:-

Program to find area of Square, Rectangle and Circle using Method Overloading

Output:
Area of the square: 37.21 sq units
Area of the rectangle: 220.0 sq units
Area of the circle: 116.8394 sq units