title: Cannot reduce visibility of method inherited method from parent
body: <p>I got this compiler error:</p>
  
  <blockquote>
    <p>You cannot reduce the visibility of a inherited method. </p>
  </blockquote>
  
  <p>I have the following code </p>
  
  <pre><code>class Parent {      
      public void func() {
          System.out.println("in Parent");
      }
  }
  
  public class TestClass extends Parent {    
      public static void main(String args[]) {
          parent obj=new TestClass();
          obj.addTest();
      } 
  
      private void func() {
          System.out.println("in child");         
      }
  }
  </code></pre>
  
  <p>Here parent class has <code>func()</code> method which is public and overridden by the subclass <code>TestClass</code> which is private. Now the compiler throws the error that I cannot the reduce the visibility. To say technically, whenever I create a object of <code>TestClass</code> assigning to the type parent object, since the <code>func()</code> method is overridden, TestClass's func() is going to get called always, then why we should take care of visibility? whats the reason behind this error ? Can someone explain me clearly ?</p>