National Academy of Engineering
- Here are the 14 grand challenges.
- Which ones are CS related?
Chapter 10: Inheritance
Introduction
- Superclass - the superset or more general class
- Subclass - the subset or more specific class
- How does inheritance differ from implementing an interface?
A subclass inherits behavior and state from the superclass.
An interface has no behavior and no state.
Methods
- Can be inherited (if they are not private)
- Can be overridden
- Can be added
Instance Variables
- All instance variables are inherited (but can't be accessed directly
if they are private)
- New instance variables can be added
Java
- Object - the superclass of every class
- extends - to create a subclass,
e.g. public class Student extends Person { ... }
- super - to access the superclass
- Person p = new Student();
- Student s = (Student) p;
- instanceof = tests whether an object belongs to a particular type
Lecture Code
In lecture today, we will build an application that defines
classes for the following scenario.
A person has a name and a birth year. A baseball player
is a person who has a team and a salary. A pitcher is a baseball
player who has an ERA. A batter is a baseball player who has a
batting average.