• 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

non static main

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


How come when I remove static modifier from main method it compiles ???
An instance method can never hide or overload a static one so why is it making an exception here!
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why shouldn't it? It's perfectly legal.

It won't work as an entry point method -- but there's nothing to prevent it from compiling.
 
S Ali
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how does it compile when the following is illegal :



and even if it didn't inherit it like the example then doesn't the compiler know that main method with String [] parameter is supposed to be static all the time ?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

S Ali wrote:An instance method can never hide or overload a static one so why is it making an exception here!



Okay, what "static one" is this instance method going to hide or overload?

Henry
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

S Ali wrote:doesn't the compiler know that main method with String [] parameter is supposed to be static all the time ?


Supposed to be? It's not. Please show me where it says that it must be.

If you want to use it as an entry point, it must conform to the rules. But it's perfectly legal Java otherwise.

It has nothing to do with your example, as there is no inheritance going on.
reply
    Bookmark Topic Watch Topic
  • New Topic