Given task is to execute main() multiple times without using any other function and without recursion() and without error. Given condition is that if executing main() n times then you can only call him (n-1) times.
Explanation: Static block is executed even before the main() executed. Here first, main() get called by static block and then JVM(Java Virtual Machine) call the main(). So, main() is executed two times by calling only one time.
- Java Multicasting (Typecasting multiple times) Puzzle
- Difference between ExecutorService execute() and submit() method in Java
- Main thread in Java
- Valid variants of main() in Java
- GFact 48 | Overloading main() in Java
- Is main method compulsory in Java?
- Replacing 'public' with 'private' in "main" in Java
- How to overload and override main method in Java
- Static Block and main() method in Java
- What are the main differences between the Java platform and other platforms?
- How to call some function before main() function in C++?
- Understanding public static void main(String args) in Java
- Does JVM create object of Main class (the class with main())?
- Understanding "static" in "public static void main" in Java
- Recursion in Java
- In Java, Can we call the main() method of a class from another class?
- Java and Multiple Inheritance
- Returning Multiple values in Java
- Times Internet Interview Experience | Set 4 (For Back-end Java Developer)
- Java | CDMA (Code Division Multiple Access)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.