General rules is that:
1) A private method cannot be overridden.
2) Subclass method should be a lower access modifier than a overridden superclass method.

But the output of the program is "I am Son". Why? Is it because of the rule 2 the output comes? If that's the case here, then two rules of overriding I mentioned above are clashing, aren't they?

Help please. Thanks.

Edited by WaltP: Requests for help are NOT Code Snippets

4 Years
Discussion Span
Last Post by JamesCherrill

it's not really being overriden, rather being 'redefined'.
as far as PrivateMethodOverride knows, there is no other method called 'Method' but the one defined within PrivateMethodOverride itself.


So technically there is a difference between redefining and overriding?


let's say, you are extending a method, and you want to run all the code that's in the parent implementation, you just want to print "End" after it.

public void printAll(){

you won't be able to do that in your example, because, as far as your child class knows, there is no Method method in your parent class.


FYI it's the same thing for static methods - because they cannot be inherited, just like private methods, you can re-define (create a method with the same name) but not override.


You'll find the link for "mark this thread solved" at the end of the thread.
You override equals for a class where you want different objects to be treated as equal according to some criteria that you define. Eg two Strings are equal if they contain exactly the same sequence of characters. It's up to you to decide exactly what values you want to compare before you decide that two objects are "equal"
I don't understand your last question about "only one code"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.