-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodsExample.java
More file actions
34 lines (28 loc) · 816 Bytes
/
MethodsExample.java
File metadata and controls
34 lines (28 loc) · 816 Bytes
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
public class MethodsExample {
//Method overloading
public int multiply(int a, int b){
System.out.println("Multiplication of " + a + " and " + b + " is " + (a * b));
return 0;
}
public int multiply(double a, double b){
System.out.println("Multiplication of " + a + " and " + b + " is " + (a * b));
return 0;
}
//Static methods
public static void staticMethod(){
System.out.println("This is a static method");
//class.staticMethod();
}
//Recursive methods
public int factorial(int n){
if(n == 0) return 1;
else return n * factorial(n-1);
}
//Pass-by-value
public static void changeValue(int n) {
n = 10;
//a = 5;
//sout -> changeValue(x);
//output = 5
}
}