Cannot reduce visibility of method inherited method from parent
<p>Today when I was doing program in inheritance I got this compiler error saying "You cannot reduce the visibility of a inherited method". I went through lot of documents and articles but still I dint get why we should not reduce the visibility.</p>

<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 please explain me clearly ?</p>
