Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
Did you just should on me? You should read this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic