This is overloading in disguise of overriding. (In case if one is not clear with the rules of overriding). I mean, the method show() in the Chat class is NOT overridden. It is overloaded.
Rule is: An overriding method must have argument lists of IDENTICAL type and order.
Let us elaborate,
1. order is out of question here as there is only one argument.
2. type must be IDENTICAL, this means IDENTICAL. "IS A" is not permitted.
Try compiling the below code which has just one change. I have added @Override annotation to the Chat class's show method. This annotation ensures that the method is ACTUALLY overridden. This means, suppose if developer intended to actually override the method from the super class but mistakenly he missed something and ended up in overloading it then his friend "@Override" annotation will help him by finding his slip EARLY (at compile time).
It is a good practice to use annotation in your code. They are your friends.
By adding the annotation @Override to this code it will not even compile and it will tell the developer that the method is NOT correctly overridden as it violated the above stated rule.
Yes you are right. The code I have posted won't compile because the method in the show() method of Chat class is not correctly overridden.
And, you don't need the @Override annotation here.
We still need it. It's always recommended to have annotations in your code. Imagine during maintenance someone trying to change the show() method in Chat class. Our friend "@Override" will be there to report the mistakes (if any).
ALWAYS have "@Override" annotation in your code when you are intending to override any method.
Yes you are right. The code I have posted won't compile because the method in the show() method of Chat class is not correctly overridden.
And, you don't need the @Override annotation here.
We still need it. It's always recommended to have annotations in your code. Imagine during maintenance someone trying to change the show() method in Chat class. Our friend "@Override" will be there to report the mistakes (if any).
ALWAYS have "@Override" annotation in your code when you are intending to override any method.
Now the output is, Parent in chat class. What I have given is method overriding. So, it uses object type.
Your program is an example of Overloading. It uses reference type.
Post by:autobot
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards