Can be add more method variable without initialize.
return_type method_name(DataType... variableName){}
class A{
public static void varArgsMethod(String... value){
sysout("Hi");
}
psvm(){
A.varArgsMethod("Welcome","Var","args"); //Can add zero or more argument
}
}
Output - Hi
Rules
ex - public void run(String... walk, int... time){}; //Compile error
ex - public void walk(int x, int... y){}
return_type method_name(DataType... variableName){}
class A{
public static void varArgsMethod(String... value){
sysout("Hi");
}
psvm(){
A.varArgsMethod("Welcome","Var","args"); //Can add zero or more argument
}
}
Output - Hi
Rules
- Only can be one Variable argument in method
ex - public void run(String... walk, int... time){}; //Compile error
- Variable Argument must be last
ex - public void walk(int x, int... y){}
No comments:
Post a Comment