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

why fields can't be overidden?????

 
rahul mehra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why fields of superclass can't be overidden??? by a subclass
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to this question, as to so many "why" questions, is "because the Java Language Specification says so".

Overriding is to do with run-time polymorphism. The Java language only implements run-time polymorphism for instance methods, not for fields or static methods. That's a choice the language designers made. They could have chosen differently, though in this case I think they chose well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic