Inheritance
Reading
Please read
- 10.1-10.9 of 10. Inheritance of Runestone book Introduction to Programming with Java by Ericson et. al.
- 8.2.1 and 8.3.1 of Runestone Java, Java, Java: Object-Oriented Problem Solving, 2024E online book by Morelli et. al.
Important concepts
- subclass, superclass (aka base class)
- inheritance
- is-a relationship
- protected access
- overriding
- class hierarchy
- abstract class
Things to consider (exercises for yourself, not to turn in)
- Why do we declare most instance variables as private, except when they are instead declared public static final? Would it be better to declare them all protected, just in case a subclass needs them? Or should we use protected only if absolutely necessary?
- What is the purpose of the special function called super? What happens when code containing a super() call runs?
- What is the point of abstract classes? Why would you ever want a class that you can’t instantiate?
Your response
What was particularly interesting, confusing, or exciting to you in this reading?