Is it possible to override a private member when subclassing in C# or Java?

private methods of a class are not visible in its child class so they won't get inherited.


This is not silly question but it gives another concept of hiding variable.

Field in Java are only hidden and not actually overridden (that doesn't mean that we'll get a compilet time error while trying this, instead they are not overridden in its true sense). Overriding means the member should be invoked based on the run time type of the object and not based on the declared type. But binding for fields in Java is always static and hence it's based on the declared type of the object reference only. Read more about Static Binding in article - Dynamic Binding vs Static Binding >>

In case of methods, only those methods are overriden which are inherited and hence static methods are also not overridden but hidden only and they follow Static Binding only. private members (methods or fields both) are neither hidden nor overridden. They also follow Static Binding and they can not be accessed directly from any other class (including sub classes) except the class which have them. Remember, Hidden doesn't mean here we can't access the members from the subclass. So, don't confuse with being not accessible (in case of private members - fields or methods) and being hidden.


No, you can't override private elements, they're effectively final (because they're never visible from a subclass to be overriden.)

You can declare private elements with the same name in the subclass, but that's not overriding the one in the superclass - it's just another private method with the same name as the one in the superclass.