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.

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(){
  super.printAll();
  System.out.println("End");
 }

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.

Got it thanks a lot stultuske :)

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.

Thanks JamesCherrill :)

James how to mark a thread as solved?

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"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.