java - Why can I override a protected method with public method? -


the java compiler doesn't complain when override protected method public method. what's happening here? overriding or hiding parent method since parent method has lower visibility?

a sub-class can widen access modifier, because still valid substitution super-class. java specification requirements in overriding , hiding:

the access modifier (§6.6) of overriding or hiding method must provide @ least access overridden or hidden method, follows:

  • if overridden or hidden method public, overriding or hiding method must public; otherwise, compile-time error occurs.
  • if overridden or hidden method protected, overriding or hiding method must protected or public; otherwise, compile-time error occurs.
  • if overridden or hidden method has default (package) access, overriding or hiding method must not private; otherwise, compile-time error occurs.

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -