Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Round Up Game Question Contradiction?

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This Round Up game is fantastic! I truly love playing it. However I came across two questions that contradict each other??? Did I misinterpret the question/answer or are one of these answers incorrect?
Question: Can a public method be overridden by a protected method?
Answer: No, Overridding a method can NOT be more restrictive than the original method.
Question: Can a method with no access modifier be overridden by a method marked protected?
Answer: Yes, Overridden methods are allowed to have LESS restriction and since protected is less restricted than the default(package) that is allowed.
Thank you,
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"protected" is more restrictive than "public."
"protected" is less restrictive than the default.
Therefore, protected can override the default (opening up access) but it can't override public (closing off access.)
OK?
[ September 04, 2003: Message edited by: Ernest Friedman-Hill ]
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest
Ernest : The default is less restrictive than protected.
I am sure you know, but just pointing out to correct it
The default is more restrictive than protected.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaaaah - sorry. I fixed my post.
Now I see why the O.P. was confused!
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, just so I totally understand, a method can be overridden as long as it's less restrictive than the method that is being overridden?
Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Less, or equally, yes; just not more.
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic