This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can main be declaired final ? why

 
varinder mahajan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can main be declaired final ? why
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes main can be declared final.....

You say why...I say why not??? Why can't be main declared final.....main is also a method like all other methods...It's just that the JVM calls the main method on executing the program...This doesn't mean that main is a special method which has restrictions on it....
 
Vinod Kumar Kommineni
Ranch Hand
Posts: 54
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this out to be clear. http://www.janeg.ca/scjp/lang/main.html
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it?
 
Sudhan Nair
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


.... i tried it ...works fine....
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sudhan Nair:
... i tried it ...works fine....

Excellent! Now to take this a step further, what exactly does this accomplish? Static methods cannot be overridden, so do you know what it means to make a static method final?
[ August 10, 2008: Message edited by: marc weber ]
 
Nabila Mohammad
Ranch Hand
Posts: 661
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

Excellent! Now to take this a step further, what exactly does this accomplish? Static methods cannot be overridden, so do you know what it means to make a static method final?

[ August 10, 2008: Message edited by: marc weber ]


Interesting Question..


I think all static methods are implicitly final , as they cannot be over riden...

Not sure..
 
Vinod Kumar Kommineni
Ranch Hand
Posts: 54
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya you are correct all static methods are implicitly final.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nabila Mohammad:
... I think all static methods are implicitly final , as they cannot be over riden...

It's true that static methods cannot be overridden, but they can be hidden. (See Overriding vs. Hiding.) The "final" modifier has a slightly different meaning when applied to a static method, but it does make a difference.
 
Saurabh Patil
Ranch Hand
Posts: 47
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

It's true that static methods cannot be overridden, but they can be hidden. (See Overriding vs. Hiding.) The "final" modifier has a slightly different meaning when applied to a static method, but it does make a difference.


Hey mark,you made a nice point. Static methods can't be over ridden but they can be hidden, anyone who knows what is method hiding can get this easily.But you said that " The "final" modifier has a slightly different meaning when applied to a static method, but it does make a difference." so can you please elaborate it more..what difference it makes?

Regards,
saurabh
 
Ronald Schild
Ranch Hand
Posts: 117
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final static methods cannot be hidden. Static methods are not implicitly final.
 
Vinod Kumar Kommineni
Ranch Hand
Posts: 54
Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i think i am wrong in making the statement that static methods are implicitly final ..there's this small difference ... we can't hide final static methods .
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Saurabh Patil
Ranch Hand
Posts: 47
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes..thats the difference...
why I didnt think about this before!

So the conclusion is.. the methods which are static but not final can be hidden and methods which are final and static cannot be hidden.

And methods which are final but not static cannot be overridden.

I think every point is covered now...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic