• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me please

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you mr.collins
reply
    Bookmark Topic Watch Topic
  • New Topic