0
Call??
How to call a method inside a switch case??
2 Answers
+ 4
As you would anywhere else, write its name followed by a pair of parentheses, and arguments inside the parentheses (when necessary).
methodName(); // no arg
methodName( arg1, arg2, ... argN ); // with args
className.methodName(); // static method from other class
objectName.methodName(); // method of other class
If you have a problem with this, then save your code and share its link in the original post Description â
https://www.sololearn.com/post/75089/?ref=app
+ 1
Let's say you have three methods:
firstMethod() from type void
secondMethod() from type int
thirdMethod(int i) with parameter.
after each case you can call this method:
int i = 3;
int value = 0;
switch(i){
case 1: firstMethod();
break;
case 2: value = secondMethod();
break;
case 3: thirdMethod(i);
break;
default: System.out.println("unknown case");
}