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

main() method

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is main() in java is final by default?
or else do we need to specify public static final void main(String args[])
correct if i'm wrong.

-Thanks & Regards,
Hamsa
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it isn't.

The final keyword on a method means that the method cannot be overridden in a subclass. But since the main() method is a static method, it can't be overridden anyway. So making the main() method final makes no sense.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A main method can also be declared final.

public static void main(String args[] { } is ok to use.
public static final void main(String args[] { } is also ok to use.



But a static method can never be overridden.
A parent class and child class can have a static method with the same signature and name. But they are not overridden methods.

A static method always hides any superclass static method with the same name.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm surprised final isn't illegal on static methods, since it doesn't actually mean anything.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While it is true that static methods can't be overridden they can be hidden. Declaring a static method final prevents that method from being hidden by a subclass. Which the compiler mistakely confuses with being unable to override the method, which isn't even possible, but who needs accurate error messages anyway...
[ March 31, 2008: Message edited by: Jelle Klap ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic