This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes main method private Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main method private" Watch "main method private" New topic

main method private

joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
I was solving a 1.4 mock exam. It had private main method and print statement in it. The answer provided is that the print statement will be executed.
I tried this on my machine but found that I was getting a runtime message that main method is not public.

I am totally confused

Please help me
bing marquez

Joined: Aug 06, 2006
Posts: 11
hi joshua,

There is only one signature of main that the JVM looks for to launch
an application, i.e. void main(String[] args) and that is must be
public and static. However you,re free to declare another method named
main in your code, apart from the main() method required by the JVM, but
with a different signature.


Anyway, can you show the code...
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Joshua,

perhaps you should show us the code. Was it perhaps something like this?


all events occur in real time
Deepak Mahboobani

Joined: Aug 17, 2006
Posts: 11
"The Java Virtual Machine Specification," which in section 2.17.1 states, "The method main must be declared public, static, and void."

Sun introduced this problem in version 1.2 of Java. As of 1.3 the problem is still there.

After a quick search for "private main" at, I found (requires login):

As you can see, the main issue is a known problem with a bug report opened against it. However, Sun has closed the bug report and the problem will NOT be fixed, "The runtime allows call to private methods, because of reflection. Fixing it will cause potential troubles."

So there you have it.

However, be careful while taking the certification exam. Last time that I checked, the proper answer to "How do you define a main?" remains: "The method main must be declared public, static, and void." Reality and the correct answer seem to disagree.
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138

As i have read main method should be public only from 1.4 or above before 1.4 it can have any access modifier.Please correct me if iam wrong.

joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
Hi All,

Thanks for your replies.

Here is the code

I agree. Here's the link:
subject: main method private
It's not a secret anymore!