java - Why does super.addAll calls the overridden add method -


i have class myhashset extends hashset class. myhashset overrides add() , addall() methods of hashset. have following code snippet:

class myhashset<e> extends hashset<e> {      @override     public boolean add(e e){        return super.add(e);     }      @override     public boolean addall(collection ? extends e> c){        return super.addall(c);     } } 

i know that, addall method implemented on add(), meaning uses add() method. so, if call myhashset's addall(), should invoke hashset's addall(), in turn should invoke hashset's add().. why calling myhashset's add(), when call myhashset's addall()?

i confused here, sorry if question silly.

this way polymorphism working.

if have class hierarchy , b b extends , have overridden method foo() when call method of subclass executed. syntax super.foo() allows calling super class's version of method. if super class's method calls bar() call version written in subclass. think it: allows inheritance work because can override methods of super class in sublass , change functionality.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -