title: why can't we assign weaker privilege in subclass
body: <p>I have a class which has a method whose access specifier by default is public. Now, I would like to extend this class in a subclass and I want to override this method to have access specifier "private". When compiling this code, I am getting a compilation error:</p>
  
  <blockquote>
    <p>"attempting to assign weaker access privileges".</p>
  </blockquote>
  
  <p>Could somebody please explain to me what is wrong with assigning weaker privileges in a subclass?</p>
  
  <p>Here is the code that caused the compilation error:</p>
  
  <pre><code>class Superclass 
  {
      void foo() 
      {
          System.out.println("Superclass.foo");
      }
  }
  
  class Subclass extends Superclass 
  {
      private void foo() 
      {
          System.out.println("Subclass.foo");
      }
  }
  </code></pre>