• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

sample q

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will be the result of compiling following code
public class MyClass
{
public static void main(String args[])
{
System.out.println("In first main()");
}
public static void main(char args[])
{
System.out.println('a');
}
}
(1) Code will not compile and will give "Duplicate main() method declaration" error
(2) Code will compile correctly but will give a runtime exception
(3) Code will compile correctly and will print "In first main()" (without quotes) when run with argument of 'a'.
(4) Code will compile correctly and will print "a" (without quotes) when run with argument of 'a'.
The corrct answer is 3. I don't see how. Can someone please explain?
Can we have more than one main() method?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One can overload the main method, but only the one with correct signature gets executed .
-Sandeep Nachane
------------------
Visit my homepage at
www.tipsmart.com
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic