Learning Outcomes
At the end of this lecture, you’ll be able to:
- Define inheritance and polymorphism and identify them in Java source code.
- Use inheritance to design simple class hierarchies that allow code to be reused for distinct subclasses.
- Explain the relationship between inheritance and type substitution (the idea of a subtype being usable in a context that expects the super type).
- Identify apparent and actual types of objects, and explain the relationship between them.
- Express how type casting works for objects, and differentiate between “Upcasting” and “Downcasting”.
- Distinguish between single, multiple, and multi-level inheritance.
- Explain the relationship between polymorphism and type substitution.
- Distinguish between dynamic (runtime) and static (compile-time) polymorphism.
- Describe how Java’s method dispatch process works.
- Develop examples of compile-time and runtime polymorphism.
- Recognize inheritance must be used to model “is-a” relationship.
- Contrast “is-a” to “has-a” relationships.
- Arrange classes in a simple class diagram that exhibits “is-a”/“has-a” relationships.
- Distinguish method overloading from method overriding.
- Explain how every object in Java has a
toString
method.
Lecture Plan
In this lecture, we'll cover the following lessons:
- The GradStudent class: Code duplication is undesirable!⚡
- The GradStudent class: Code reuse through Inheritance
- The GradStudent class: Inheritance syntax in Java
- Inheritance: The nuances!⚡
- Inheritance: Symmetric relationship?⚡
- Java Interlude: Selective inheritance?
- Inheritance: Transitive relationship?⚡
- Java Interlude: Multiple inheritance?
- Inheritance: Type hierarchy⚡
- Inheritance: Type substitution⚡
- Type hierarchy: Casting of types
- Type hierarchy: Apparent vs. Actual Type⚡
- Polymorphism: Static or compile-time⚡
- Polymorphism: Dynamic or runtime⚡
- Polymorphism: Exercise⚡
- Java Interlude: Method Overriding
- Inheritance: Is-a relationship⚡
- Java Interlude: The Object class
Lessons marked with ⚡ contain exercise/activity.