Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding

 
Jeet Jain
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I dont understand why "static final" prevent compilation?
 
Jeet Jain
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
08. is an instance method and 04. is static. Its not overriding it. Just hiding it, right?
 
gihan dissanayaka
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@JJ
it's because you can't override static final methods .
 
Suhrid Karthik
Ranch Hand
Posts: 58
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeet Jain wrote:

I dont understand why "static final" prevent compilation?


Forget about the final keyword for the moment. An instance method cannot "override" a static method. Similarly a static method cannot "hide" instance methods - only static methods.
Now assuming growFast() was static in Thistle, then the final keyword will come into play - it prevents the subclass static method from "hiding" the superclass static method.
 
Jeet Jain
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic