| Author |
JQ+ 953840006570
|
Peter Wang
Greenhorn
Joined: Jan 16, 2002
Posts: 7
|
|
Hello all, Just working through JQ+ to prepare for the certification. Ran across this question: ... Which modifiers would be valid in the declaration of a main() method so that the class can be run from command line? a)native b)protected c)public d)final e)abstract ... Correct answers are a, c and d. I had chosen b instead of a. The explanation indicates that although b would work, it is not valid for the purpose of the certification. Can we expect other similar types of question like this, where the correct answer (or one of the correct answer) is not valid?
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
No I don't think you can expect such question but it's always good to know how it really is... For the purpose of the exam, the JLS tells you the absolute truth and that's the sole source of information you should trust... HIH [ January 19, 2002: Message edited by: Valentin Crettaz ]
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Bob E. Lee
Ranch Hand
Joined: Jan 15, 2002
Posts: 36
|
|
a)native b)protected c)public d)final e)abstract ... Correct answers are a, c and d.
Hmmm I test it out the "native" but got some error.. Chapter1test.java:5: native methods cannot have a body native static void main(String arg[]){ Of coure I test the file and it compiles fine w/ protected, final and public. I did it in my command line (DOS) Bob
|
 |
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
|
|
Bob, the native modifier signifies to the compiler that you will be implementing the method body in native code. Your main method declaration if defined native would look like this: public static native void main(String[] args); Note the semi-colon. The declaration is similar to an abstract declaration in that you use a semicolon and no method body. Now, just including the native modifier isn't enough; you have to actually provide a library that includes the native code. Native code is usually written in C or C++ although it doesn't have to be. Rob
|
Rob
SCJP 1.4
|
 |
Paul Salerno
Ranch Hand
Joined: Jan 17, 2002
Posts: 172
|
|
Valentin- What did you mean by "For the purpose of the exam, the JLS tells you the absolute truth and that's the sole source of information you should trust..." What is the JLS, and how is this available for the exam? Thanks! -Paul
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
Paul, The JLS is the Java Language Specification written by Sun Microsystems. You can get it at http://java.sun.com/docs/books/jls/second_edition/html/jTOC.doc.html. You should read it (or parts of it) if you really want to master the details of the Java Language. There are lots of useful resources in there. Some sections are a little cryptic (read, mathematically heavy) but it is really worth reading it... Take your time.. HIH [ January 21, 2002: Message edited by: Valentin Crettaz ]
|
 |
 |
|
|
subject: JQ+ 953840006570
|
|
|