Java inheritance: Reducing visibility in a constructor vs inherited method -


in following code, constructor of child has reduced visibility public private, allowed. inherited methods, such test(), cannot have reduced visibility. why java operate way?

class parent {          public parent(){}         public void test()           {               system.out.print("parent test executed!");           } }  class child extends parent{        private child(){}      private void test(){         system.out.print("child test executed!");      }      }   

constructors not inherited, child() doesn't override parent().

as methods, if have (if child() public)

parent p = new child(); p.test(); 

had been allowed, invoking private method. narrowing access while overriding not permitted.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -