-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionOverloadingTest.java
More file actions
73 lines (63 loc) · 1.47 KB
/
Copy pathFunctionOverloadingTest.java
File metadata and controls
73 lines (63 loc) · 1.47 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Function overloading/early binding/ early loading based on
* 1. types of parameters
* 2. no of parameters
* 3. sequence of parameters
*
*
*
*
*
*
*Constructor
*What - function whose name is same as class name, no return type
*used for initialize object
*invoked during object creation
*
*you can have either implicit or explicit constructor but not both at same time
*class A {} //imploicit
*
*class A
*{
* A(int a)
* {
*
* }
*}
*
* Function overloading is not possible with return type
*
*/
public class FunctionOverloadingTest {
public static void main(String[] args) {
Distance distObj = new Distance();
distObj.calculateDistance();
distObj.calculateDistance(10, 02);
distObj.calculateDistance(12, 5.0f);
distObj.calculateDistance(12.0f, 10);
distObj.calculateDistance(4.0f, 2.0f);
}
}
class Distance
{
void calculateDistance()
{
System.out.println("Distance is 0 since no parameters passed");
}
void calculateDistance(int speed, int time)
{
System.out.println("Distance is :"+(speed*time)+" km");
}
void calculateDistance(int speed, float time)
{
System.out.println("Distance is: "+(speed*time)+" km");
}
void calculateDistance(float speed, int time)
{
System.out.println("Distance is: "+(speed*time)+" km");
}
void calculateDistance(float speed, float time)
{
System.out.println("Distance is: "+(speed*time)+" km");
}
}