-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathProgram.java
More file actions
37 lines (34 loc) · 1.12 KB
/
Program.java
File metadata and controls
37 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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);
}
}