COMPSCI 61B Lecture Notes - Lecture 8: Hyponymy And Hypernymy, Method Overriding
Document Summary
Java allows multiple methods with the same name but different parameters. But while overloading works, it is a bad idea. Any change made to one must be made to the other. Suppose we make another list someday, we"ll need yet another function. In natural languages, we have a concept known as hypernym to deal with this problem. We use the word hyponym for the opposite type of relationship. Expressing this in java is a 2 step process: define a reference type for our hypernym list 61b, use the new keyword interface instead of class to define a list61b i. If a subclass has a method with the exact same signature as in the superclass, we say that the subclass overrides the method. Methods with the same name but different signatures are overloaded. In 61b, we"ll always mark every overriding method with @override. The only effect of the tag is that the code won"t compile if it isn"t actually overriding.