File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can main be declaired final ? why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can main be declaired final ? why" Watch "can main be declaired final ? why" New topic
Author

can main be declaired final ? why

varinder mahajan
Ranch Hand

Joined: Jun 11, 2008
Posts: 47
can main be declaired final ? why


Beat the world,if you can.......
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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....


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Vinod Kumar Kommineni
Ranch Hand

Joined: Jun 12, 2008
Posts: 54

check this out to be clear. http://www.janeg.ca/scjp/lang/main.html


Regards
vinod SCJP 6.0
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

Have you tried it?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sudhan Nair
Greenhorn

Joined: Jun 28, 2008
Posts: 6


.... i tried it ...works fine....


The only difference between Artistic and Insane : SUCCESS.....
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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..


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Vinod Kumar Kommineni
Ranch Hand

Joined: Jun 12, 2008
Posts: 54

ya you are correct all static methods are implicitly final.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Dec 11, 2005
Posts: 45

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


All for one and one for all!
Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
Final static methods cannot be hidden. Static methods are not implicitly final.


Java hobbyist.
Vinod Kumar Kommineni
Ranch Hand

Joined: Jun 12, 2008
Posts: 54

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

Joined: Aug 31, 2004
Posts: 11343

Saurabh Patil
Ranch Hand

Joined: Dec 11, 2005
Posts: 45

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
 
subject: can main be declaired final ? why
 
Similar Threads
NX: How to deal with IOException when not declaired to be thrown.