0

Call??

How to call a method inside a switch case??

1st Mar 2022, 7:38 AM
Zeref Dragneel
Zeref Dragneel - avatar
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
1st Mar 2022, 7:46 AM
Ipang
+ 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"); }
1st Mar 2022, 4:08 PM
Denise Roßberg
Denise Roßberg - avatar