How to access a non static method in an abstract class's static method?

Why is the main method in Java public?

  • What is its use if the class containing the main method is itself default (no access specifier)? How JVM is able to access a main method in a default class? If in any class a method is public and the class containing that method is itself default(i.e. no access specifier) then we know that method can not be accessed by any class outside the package. So how JVM is able to execute main method when we write it into a non public or default class?

  • Answer:

    http://docs.oracle.com/javase/specs/jls/se7/html/index.html says nothing about the type of the class which contains the main method. However, main method must be public. (See section 12.1 from the specification.) The main method being static, the JVM can call the method without creating an instance of the class containing it. Hence the class being non-public does not make a difference as far as the entry point of JVM is concerned.

Aniket Garg at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.