Can we access the public method defined in the default class outside the package in java?

The main method in java is defined as a public method, and this method is defined in the class by default. let's say

class test{ public static void main(String args[]){ System.out.println("Hi"); } } 

can you explain how the JVM can access this main method since the class is by default and can only be accessed in the package.

0
java
Jul 22 '11 at 19:14
source share
1 answer

You see the JVM as a bunch of Java code in another package, so you could not access the main method, hidden in your class, with default accessibility. But this is not so. JVM - a virtual machine running Java code; he decides what is and is not available for other Java code. In particular, he can run any methods that he likes, regardless of their availability.

+4
Jul 22 '11 at 19:24
source share



All Articles