top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Does Java Virtual Machine create object of Main class (the class in which main() is present) ?

+1 vote
340 views
Does Java Virtual Machine create object of Main class (the class in which main() is present) ?
posted Aug 5, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

No, JVM doesn't create object of the main class.In java main() is static to make sure it will be called without any instance. So it means there is no need of object to execute main() method.

Check below program:-

abstract class MainClass {
    public static void main(String args[])
    {
        System.out.println("Inside Main Method");
    }
}

Output: Inside Main Method

Since we cannot create object of abstract classes in Java, it is guaranteed that object of class with main() is not created by Java Virtual Machine.

answer Aug 5, 2016 by Salil Agrawal
...