-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirst.java
More file actions
38 lines (33 loc) · 851 Bytes
/
Copy pathFirst.java
File metadata and controls
38 lines (33 loc) · 851 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
35
36
37
38
/*
* It stands for variable argument methods.
* In java language, if we have variable number of arguments, then copulsorily new method has to be written till jdk 1.4v
* But jdk 1.5v we can write single method which can handle variable number of arguments
* but all of them should be of same type.
*
* Internally var-arg method will convert to SingleDimension array so we can
* access the var arg method arguments using index
*
* Syntax:- methodName(dataType... variableName)
*/
//Example:-
class Sum
{
public void add(int... x)
{
int total=0;
for(int i=0;i<x.length;i++)
{
total+=x[i];
}
System.out.println("Sum is: "+total);
}
}
public class First {
public static void main(String[] args) {
Sum s=new Sum();
s.add();
s.add(10);
s.add(10,20);
s.add(10,20,30);
}
}