File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt it or not? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt it or not?" Watch "Doubt it or not?" New topic

Doubt it or not?

Roger Zhao
Ranch Hand

Joined: Aug 05, 2003
Posts: 73
Hi, all:
Q:In order for a source code file, containing the public class Test, to successsfully compile, which of the following must be true?
Here is a option :
(a)It must declared a public class name Test.
As I known, a file with a class with default modifier can also compile and run successfully.
Choose (a) or not? In my opinion, I will choose it even if the fact above exists.

"There is a will,there is a way!"<br />SCJP1.4
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
From the JLS, §12.1.4 Invoke Test.main:

The method main must be declared public, static, and void. It must accept a single argument that is an array of strings.

I realize that some compilers will execute even if the main method doesn't include the keyword public but, according to the JLS, it must be public. Therefore, as far as the exam is concerned (because the exam is based on the JLS, not every Java compiler on the market), the answer is that the main method MUST be public.
I hope that helps,

SCJP Tipline, etc.
Max Habibi
town drunk
( and author)

Joined: Jun 27, 2002
Posts: 4118
As I understand it, this was never an enforced constraint until jdk 1.4. However, it is certainly the way things are supposed to work.

Java Regular Expressions
I agree. Here's the link:
subject: Doubt it or not?
It's not a secret anymore!