+ 2

(Java) how can I execute a method from inside another method?

I want to run a method and then run another method automatically after that method is finished?? TIA

6th Jan 2019, 3:58 PM
Alex
Alex - avatar
1 Answer
+ 8
Assuming you have method A and method B, and you want method B to immediately run after method A has been executed. All you need to do is to call method B on the last line of the method A. private void A() { system.print.outln("First"); B(); // executes method B. } private void B() { system.print.outln("Second"); } Then call A(); from the main method. Note, the return type must be void, but if it is not you should call the method B before the return keyword. Since the return keyword will terminate the program execution. Alternatively you can call method A & B simultaneously from the main method. Static void Main(args){ A(); B(); } I hope this helps. Regards...
6th Jan 2019, 4:47 PM
africana
africana - avatar