Saturday 8 September 2018

Can we Override private methods in Java.

          We can not override the private methods because scope of the private access specifier is only within the class. By the definition of overriding,when we want to override something, then there should be inheritance concept means we should have parent and sub class.When super class method is private that will not be visible to subclass, whatever the methods we are writing in sub class will be treated as new method and not a overridden method.
For example, We have written a private method in parent class and same method, we are trying to access in child class but compiler giving the error, thus we can say that we can not override private method.


No comments:

Post a Comment