Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me please

 
Arunan Ramanathan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Collins Mbianda
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Arunan Ramanathan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you mr.collins
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic