Does JVM create object of Main class ?

Price: INR 8,999.00
Price: INR 15,999.00
Was: INR 16,999.00

Does JVM create object of Main class ? It’s a common and important Interview Question in Java or Automation QA Interview. The answer of this is “NO“, JVM doesn’t create the Object of the Main Class.

 

Let’s consider the following program:-

Output:

Hello

 

We have studied that the reason for main() static in Java is to make sure that the main() method can be called without any instance. To justify the same, we can see that the following program compiles and runs fine.

Output:

Hello

 

Since we can’t create object of abstract classes in Java, it is guaranteed that object of the class with main() is not created by JVM.

0 Comment

Leave a Reply