Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method overridden or not

 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact text of the compiler error?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's -



Regards,
Dan
 
Himai Minh
Ranch Hand
Posts: 1296
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all !! Got it !! thanks friends
 
Kancharla Madhu
Ranch Hand
Posts: 109
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Alex Benedict
Greenhorn
Posts: 16
Chrome Eclipse IDE Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declaring it final is i think the cause of the problem.
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic