• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

static modifier doubt

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



The above code is given in chapter 2, page no:147. It gives input a a a. But I got runtime exception:Exception in thread "main" java.lang.NoSuchMethodError: main

Can anyone explain?
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would have had both the classes defined in the same java file named StaticTest.java.Here in StaticTest.java has one public class StaticTest and one default class Static. After compilation two class files will be generated StaticTest.class and Static.class.
And now you would have run the below cmd
java StaticTest
This will result in the exception , because the class StaticTest does not have the main method.

Fix would be do swap the access modifiers of the classes and rename the class to Static.java
OR
java Static
will give the desired result. This will now look for the main() in Static.class and will find and execute it.

Thanks
Deepak
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Deepak. I got it.
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic