Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusing question in the Rules roundup game of JavaRanch

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I encountered the following question in the Rules Roundup.
(#333)TRUE or FALSE: an overriding method can change
the access modifier from default to protected.
Answer: TRUE
Since the protected modifier is less restrictive than
default, an overriding method is allowed to make that
change.

MY understanding that is when we override methods, we cannot make the overriding method more restricted.
Isn't Protected more restrictive than Default, which i assume is Friendly or Package.
-Hemanth

 
Sagar Sharma
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
friendly is more restrictive than protected because it dooes not allow access outside the package. Protedted features are allowed access outside the package provided that the overriding method is in a subclass of the base class..

Hope it helps
Sagar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic