Hi ppl, If we go by the defn of access modifiers whenever a method is denoted as private it means that it can be accessed from within a class only. now what i did was i tried the private access modifier for PSVM(String args[]){} and it worked. what i would like to know is how does the PSVM method fit into all this and where does the method lie exactly for it to work even with a private access modifier.
Alfred Kemety
Ranch Hand
Joined: Aug 14, 2002
Posts: 279
posted
0
According to the JLS it should not work with a private modifier, but still some compilers and JVM work fine if you use the private modifier, it shouldn't though... Rule of the thumb, follow the JLS in the code you're writting so that you will have no problem with any compilor, JVM
According to the JLS it should not work with a private modifier
That's exactly what i thought that it should not work but it does and i kinda wanted to know why and how it does work even in a few compilers that it works on. i am not using the access modifier in any of my code and i stick to the JLS but why private SVM(String args[]) works is something i feels depends on how the JVM is built and the ClassLoader invocations. any light on this by anyone who knows why it works will be very much appreciated.
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
It's a hole in the implementation. It's always been like that and if they changed now it might cause problems to existing code.
In fact, they did change it to conform to the previously-existing spec, as of 1.4. Try creating a private main method now - you get "main method not public". Older JDKs allowed it, but not the latest ones.
"I'm not back." - Bill Harding, Twister
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
It still compiles but you get the error message when you attempt to run. This solution is worse than treating private main methods as public.