-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecond.java
More file actions
76 lines (71 loc) · 2.24 KB
/
Copy pathSecond.java
File metadata and controls
76 lines (71 loc) · 2.24 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* 1. Case-1> Valid Signature
*
* i) public void methodName(int... x)
* ii)public void methodName(int ...x)
* iii)public void methodName(int...x)
*
* 2. Case-2>We can mix normal argu. with var-arg but var-arg must be always last.
*
* i) public void methodName(int... x, int y) //Invalid
* ii) public void methodName(String s,int... x)// valid
* iii)public void methodName(int x,int...y) ///valid
*
* 3. Case-3> In an argument list there should be only one var arg
*
* i) public void methodName(int y, int...z) //valid
* ii) public void methodName(int...x , int... y) //invalid
*
* 4. Case-4> We can overload var arg method but var arg method will get a call only if none of
* matches are found. (just like default statement of switch case.)
*
* 5. Case-5> No two same signature method can me exist in one class
* eg:
* public void m1(int... x) --->internally--> m1(int[] x)
* public void m1(int[] x)
*
* both method signature is same and hence they can not exist in same class at a same time
*
* Note:
* i)Whereever SingleDimension array is present we can replace it with var arg.
* eg: public static void main(String[] arg)---> (String... arg)
*
* ii)Whereever var arg is present we can not replace it with SingleDimension array/
* eg:public void add(int... x)---> (int[] x)-->invalid
*
*
* Because:
* m1(int... x)=> we can call to this method by passing group of int values or 1D array and
* x will become 1D array internally (int[] x)
* m1(int[] x)=> we can call to this method by passing 1D array only.
*/
public class Second {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
/*
* Note:
* To accept the multiple arguments of 1D array then we have to make the ellipse of 1D array
* eg: public void methodName(int[]... x)--->internally(int[][] x)
*
* eg:
* class Test
* {
* public void m1(int[]... x)
* {
* for(int[] i:x)
* {
* for(int ele: i)
* System.out.println(ele);
* }
* }
* public static void main(String... s)
* {
* Test t=new Test();
* int[] a={10,20};
* int[] b={30,40};
*
* t.m1(a,b);
* }
* }
*/