Write a program to overload subtract method with various parameters in a class in Java
CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | public class ques2 {
public static void subtract(int a,int b){
int res = a-b;
System.out.println("Subtract "+res);
}
public static void subtract(int a ,int b ,int c){
int res = a - b - c;
System.out.println("Subtract "+res);
}
public static void main(String[] args) {
subtract(25,10);
subtract(25,10,30);
}
}
|
OUTPUT
Subtract 15
Subtract -15
Tags:
Java