Skip to content

Commit 3d93a0a

Browse files
authored
Update 2022-10-31-method-overloading-in-java.md
1 parent 3376d4b commit 3d93a0a

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

‎_posts/java-interview-questions/core-java-interview-questions/2022-10-31-method-overloading-in-java.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ For example `add(int a, int b)` or `add(int a, int b, int c)` or `add(double a,
2121

2222
> **What Is Method Signature In Java?**
2323
>
24-
> In Java, method signature contains method name and type of arguments.
24+
> In Java, the method signature contains the method name and type of arguments.
2525
>
2626
> method-name(argument-type-1, argument-type-2...)
2727
>
2828
> Ex. `getData(int, String)`
2929
>
30-
> **Note:** In java, the method signature does not include the name of parameter, it only includes it's datatype.
30+
> **Note:** In Java, the method signature does not include the name of the parameter, it only includes its datatype.
3131
3232
---
3333

3434
Compile-time polymorphism can be achieved by Method overloading.
3535

3636
In Java, there are two ways to overload the method.
3737

38-
1. By changing number of arguments
38+
1. By changing the number of arguments
3939
2. By changing the data type of arguments
4040

41-
## 1. By changing number of arguments
41+
## 1. By changing the number of arguments
4242

4343
We can overload a method **by changing the number of arguments i.e parameters it receives**.
4444

@@ -47,13 +47,13 @@ As shown in the example from the introduction, we can overload the method `add(i
4747
```java
4848
public class Operation{
4949

50-
public static int add(int a, int b){
51-
return a+b;
52-
}
53-
54-
public static int add(int a, int b, int c){
55-
return a+b+c;
56-
}
50+
public static int add(int a, int b){
51+
return a+b;
52+
}
53+
54+
public static int add(int a, int b, int c){
55+
return a+b+c;
56+
}
5757

5858
}
5959
```
@@ -67,13 +67,13 @@ As shown in the example from the introduction, we can overload the method `add(i
6767
```java
6868
public class Operation{
6969

70-
public static int add(int a, int b){
71-
return a+b;
72-
}
73-
74-
public static double add(double a, double b){
75-
return a+b;
76-
}
70+
public static int add(int a, int b){
71+
return a+b;
72+
}
73+
74+
public static double add(double a, double b){
75+
return a+b;
76+
}
7777

7878
}
7979
```

0 commit comments

Comments
 (0)