• 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

Is the main method inherited??

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Base
{
static class Inner
{
public static void main(String[] args)
{
System.out.println("Inner");
}
}
}

public class MainTest extends Base.Inner
{
}
when MainTest is run, it prints 'Inner'.
Ok, by the rules of inheritance and etc.. I can arrive at an answer.
But I thought this main is a special method, and that it should be associated per class.
I want to know if this is a bug??
Thanks.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No it is not a bug. main method is a normal method.
The JVM just call the method with at least the following signature: static void main(String[])
If any public class in a java source, it will be called the main there, not the others possible mains.
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
question:
JVM will only run the main method of a top level class only. right ?
if Inner were not static then would the main method would not be run as the class Inner would no longer be TOP-LEVEL. right ?

Originally posted by Jose Botella:
No it is not a bug. main method is a normal method.
The JVM just call the method with at least the following signature: static void main(String[])
If any public class in a java source, it will be called the main there, not the others possible mains.

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

Originally posted by mark stone:
question:
JVM will only run the main method of a top level class only. right ?
if Inner were not static then would the main method would not be run as the class Inner would no longer be TOP-LEVEL. right ?

 
reply
    Bookmark Topic Watch Topic
  • New Topic