CS 2110 Recitation Notes

Lecture 5: Inheritance

Subclasses

A subclass is a child of another class.

Example:

public class InterestAccount extends Account

<aside> 💡 A class has at most one direct superclass

</aside>

A class hierarchy diagram shows how subclasses point to parent classes.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1766d82a-c49c-41d8-81ae-fd4ca2285372/Untitled.png

Inheritance

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/83b644f2-ea08-4749-a9d5-90240c2ff420/Untitled.png

The $\texttt{super}$ keyword invokes a method of a class's parent using the bottom up rule.

Overriding

The $\texttt{@Override}$ annotation indicates the author's intent to override a method so it's not just accidental.