You cannot reduce the visibility of a inherited method. I have the following code class Parent { public void func() { System ...Meaning of "Cannot reduce the visibility of the inherited method ...java - Error "Cannot reduce the visibility of a inherited method" while ...Java, Cannot reduce the visibility of the inherited method from objectOverriding method with a lower-visibility one results in compilation ...Autres résultats sur stackoverflow.com
Why we Cannot reduce the visibility of the inherited method?
You cannot reduce the visibility of a inherited method. Here parent class has func() method which is public and overridden by the subclass TestClass which is private. Now the compiler throws the error that I cannot the reduce the visibility.
Can we change the visibility of method while overriding?
First, when you override methods in a subclass, the overriding method must be at least as visible as the overridden method. While it is possible to take a private method and override it with a public method in a subclass, the reverse is not possible; you can't override a public method with a private method.
What does an inherited method need to be for a subclass to override it?
To override an inherited method, the method in the child class must have the same name, parameter list, and return type (or a subclass of the return type) as the parent method. Any method that is called must be defined within its own class or its superclass.