File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me please 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 "Help me please" Watch "Help me please" New topic
Author

Help me please

Arunan Ramanathan
Greenhorn

Joined: Jul 31, 2007
Posts: 24
9.What would be the results of compiling and running the following class. Select the one correct answer.

class test {
public static void main() {
System.out.println("test");
}
}


a.The program does not compile as there is no main method defined.
b.The program compiles and runs generating an output of "test"
c.The program compiles and runs but does not generate any output.
d.The program compiles but does not run.

I got the above question from a question dump and they put the answer as (d)
The method signature is wrong then how does this code compiles?


Scjp 1.4 - 80%
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
The programm will compile.

The code is equivalent to



But it cannot run since the exact main method is not founded:


[ August 22, 2007: Message edited by: Collins Mbianda ]

SCJP 5.0 | SCWCD 1.4
Arunan Ramanathan
Greenhorn

Joined: Jul 31, 2007
Posts: 24
This is another problem

Which of the following are valid declarations for the main method. Select the three correct answers.
a.public static void main(String args[]);
b.public static void main(String []args);
c.final static public void main (String args[]);
d.public static int main(String args[]);
e.public static abstract void main(String args[]);

they gave the answer as :a,b,c

In the answer c i got a doubt..can we declare a main method as final?
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
c is also true: the modifier final can be used for the main method.

When a method is final it mean that it cannot be overriden.
As any one don't ovveride the main method, c is true.
Arunan Ramanathan
Greenhorn

Joined: Jul 31, 2007
Posts: 24
Thank you mr.collins
 
GeeCON Prague 2014
 
subject: Help me please