Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wonder!!!!

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class abc
{
public void display()
{
System.out.println("Abc");
}
public void display(int a)
{
System.out.println("int");
}
private static void main(String[] args)
{
System.out.println("Hello World!");
}
}

This code works fine for JDK1.3 evevn if main is private.but fails to run on JDK1.4 saying "Main is not public".

The question is How it is possible to invoke main method from startup code evenif it is private? or i am misunderstanding something?


Thanks in advance
Shrinivas
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"How is it possible?" Remember that nothing marks a method private other than a flag in the class file; it's not as though it's hidden or encrypted or the class will bite you with three inch fangs if you call a private method. The application launcher doesn't have to follow the normal Java access rules, as it's not a Java program itself.

Regarding why it works in 1.3 vs. 1.4: it's always been required that main() be public, but this requirement hasn't always been enforced. Now it is.
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrinivas Mujumdar:

The question is How it is possible to invoke main method from startup code evenif it is private? or i am misunderstanding something?


Who said that JVM must play by the rules? After all, JVM is the one who makes the rules work
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Well the question is about the consisteny of rules. wheather it is Normal application or JVM itself.I do agree with Ernest about enforcing the rule in JDK1.4. One intresting stuff is in jdk 1.4 it simply flashes a message i.e. Main is not public it do not display any Error message. wheather it uses Assertion ?


Shrinivas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic