• 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

Main method

 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I just bought Khalid Mughal and Rolf Rasmussen's book "Java Certification". In one of the chapters, it says "main method can be overloaded...". I wrote a simple code to test but it generated a run-time exception: "Exception in thread main java.lang.NoSuchMethodError: main".
Would anybody know if this is an error in the book or is this something new to sun's jdk 1.4? There's no errata yet on the book's website. I'm using 1.4.2_01.
Thanks.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you overload it or replace it? You can overload main but you still a main method that takes an array of Strings as a parameter.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must have deleted the original main() method instead of overloading it.
Thanks,
Gopesh
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys. Yes I mistakingly deleted it. Now it doesnt throw any exception anymore. But I couldnt get the overloaded method to run. But that's ok, I dont see any reason why anybody would want to do that.
Thanks.
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a good question, because the exam might just try to trick you about main...
and remember you can also have a class that looks like this:
public class Foo {
public static void main (String args) { }
}
and it is perfectly legal.
Of course, you can't run it from the command-line -- but you can treat it as any *other* method in a class.
So you can overload main, you can have a class with a different main signature, etc. and the only problem is that you can't use those as your bootstrap main methods called by the JVM.
cheers,
Kathy
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It's a good question, because the exam might just try to trick you about main... and remember you can also have a class that looks like this:
public class Foo {
public static void main (String args) { }
}
and it is perfectly legal.
Of course, you can't run it from the command-line -- but you can treat it as any *other* method in a class.
So you can overload main, you can have a class with a different main signature, etc. and the only problem is that you can't use those as your bootstrap main methods called by the JVM.
cheers,
Kathy


I got the veery same question on the exam..!!!
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cathy! I'm using your book too. Its a very good book. Great job
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic