aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static method overridden or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static method overridden or not" Watch "static method overridden or not" New topic
Author

static method overridden or not

vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Namaste Friends !!

Please tell me why this program is giving compile error ??



Polymorphism doesn't apply on static method and if static method can't be overridden then why it is giving compile error on being declared final??

Please explain....
Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

What is the exact text of the compiler error?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
It's -



Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 800
    
    1
Static methods can be redefined in a child class.
Final means the method cannot be redefined.

Reference:http://stackoverflow.com/questions/1743715/behaviour-of-final-static-method
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
vishal mishra wrote:
Polymorphism doesn't apply on static method and if static method can't be overridden then why it is giving compile error on being declared final??


Because we have here a double offense - static and final.

Regards,
Dan
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Thank you all !! Got it !! thanks friends
Kancharla Madhu
Ranch Hand

Joined: May 06, 2012
Posts: 109


I do not see any reason for Compiler Error, I just tried compile and run the file found no error at all.Only inherited instance methods could be Overridden.


Champions arenĀ“t made in the gyms. Champions are made from something they have deep inside them - a DESIRE, a DREAM, a VISION
Alex Benedict
Greenhorn

Joined: Apr 12, 2013
Posts: 16

Declaring it final is i think the cause of the problem.
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Kancharla Madhu wrote:
I do not see any reason for Compiler Error, I just tried compile and run the file found no error at all.Only inherited instance methods could be Overridden.


Namaste Kancharla,

Code given above will not compile, paste your code which compiled without error....



Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static method overridden or not