Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

qs#333 of RRU  RSS feed

 
Nalini Mistry
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer says that a default method can be overridden with a protected method coz less restrictive is allowed. From what i have studied, more restrictive is allowed, less restrictive isnt. Please clarify.
 
paul wheaton
Trailboss
Posts: 22531
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, the game is correct. Less restrictive is allowed.
Think of polymorphism. If you made it more restrictive, would stuff that is not directly aware of the more restrictive method be allowed to have access? Nope. Therefore, you have a breakdown of polymorphism. If you allow less restriction, polymorphism still works!
One way to be sure -- warm up that compiler and try it out!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!