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

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 ]
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic