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 voodoo exam_1 question 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 "voodoo exam_1 question" Watch "voodoo exam_1 question" New topic

voodoo exam_1 question

bani kaali
Ranch Hand

Joined: May 05, 2002
Posts: 42
By changing which line in the following code can you make the class compile with no errors?
class Xtc {
protected static void main(String args[]) {//line 1
byte b = 10, //line2
c = 10 , //line 3
x= (byte) (b + c) ; //line 4
System.out.println(" x is " + x); //line5
a) line 1
b) line 2
c) line 3
d) line 4
e) line 5
f) None , the class compiles with no error and prints 20
He says the ans is (f) None
I marked it as (a) since main() must be public as the class will compile only if line1 is changed to public static void main ( String args[])
can anyone tell me why the answer is none, i tried compiling the program but compiler says main must be public and static.
thanks in advance.
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
the answer should to be error in the line of main method declaration. since main() has to be declared public and static.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The Java Language Specification does indeed state that the main method must be declared public, static, void and have a single argument that is an array of Strings. However, it is usually the JVM that enforces the rule. For that reason, a Sun compiler will compile the code as long as it is a legal method declaration, but the JVM will throw a runtime error if an attempt is made to invoke the main method from the command line.
Older versions of the JDK do not enforce some of the rules, so it is possible to get a variety of results if you attempt to compile and run the code. However, for the purposes of the exam, the rules specified in the Java Language Specification must be enforced.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
bani kaali
Ranch Hand

Joined: May 05, 2002
Posts: 42
Thanks Zarina.
Don,thanks for the explanation.
Your exams are of great help to people like me who are preparing for SCJP.You have done a great job.Thanks again Don.
I agree. Here's the link:
subject: voodoo exam_1 question
It's not a secret anymore!