You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/docs/method-overloading.mdx
+8-2Lines changed: 8 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,9 @@ title: Java Method Overloading
3
3
description: In this tutorial, we will learn how to implements methods overloading or function overloading in Java.
4
4
---
5
5
6
-
## Java Method Overloading
6
+
import { TipInfo } from"@/components/Tip";
7
+
8
+
## What is Method Overloading in Java?
7
9
In Java, method overloading allows multiple methods with the same name but different parameter lists to coexist in the same class. This can involve variations in the number or types of parameters, or both. Overloaded methods provide flexibility by offering different ways to call a method, depending on the parameters passed.
8
10
9
11
### Example:
@@ -114,4 +116,8 @@ class HelperService {
114
116
- Overloading is achieved by varying either the number or type of parameters.
115
117
- Changing only the return type does not constitute overloading; there must be a parameter difference.
116
118
117
-
**Tip:***Constructor overloading in Java works similarly to method overloading.*
119
+
<TipInfo>
120
+
121
+
**Tip:***Constructor overloading in Java works similarly to method overloading.*
Copy file name to clipboardExpand all lines: src/pages/docs/methods.mdx
+35-25Lines changed: 35 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -3,16 +3,18 @@ title: Java Methods
3
3
description: In this tutorial, we will learn how to implements methods or functions in Java.
4
4
---
5
5
6
-
## What is a method in Java?
6
+
import { TipInfo } from"@/components/Tip";
7
+
8
+
## What is a Method in Java?
7
9
8
10
In Java, a method is a collection of statements designed to perform specific tasks and, optionally, return a result to the caller. A Java method can also execute a task without returning any value. Methods enable code reuse by eliminating the need to retype code. Importantly, in Java, every method must belong to a class.
9
11
10
-
###Types of Methods in Java
12
+
## Types of Methods in Java
11
13
12
14
-`User-defined Methods`: Custom methods created by the programmer based on specific requirements.
13
15
-`Standard Library Methods`: Built-in methods provided by Java, ready for immediate use.
14
16
15
-
###Declaring a Java Method
17
+
## Declaring a Java Method
16
18
17
19
The basic syntax for a method declaration is:
18
20
@@ -25,7 +27,7 @@ returnType methodName() {
25
27
2.**methodName:** The identifier used to call the method.
26
28
3.**method body:** Code inside `{ }` that defines the task to be performed.
27
29
28
-
####Example 1:
30
+
### Example 1:
29
31
30
32
```java
31
33
int addNumbers() {
@@ -34,7 +36,7 @@ int addNumbers() {
34
36
```
35
37
In this example, `addNumbers()` is the method name, and its return type is `int`.
0 commit comments