8.1 Inheritance Basics
Socrates is a person.
All people are mortal.
Therefore socrates is mortal.
—TYPICAL SYLLOGISM
Suppose we define a class for vehicles that has instance variables to record the vehicle’s number of wheels and maximum number of occupants. The class also has accessor and mutator methods. Imagine that we then define a class for automobiles that has instance variables and methods just like the ones in the class of vehicles. In addition, our automobile class would have added instance variables for such things as the amount of fuel in the fuel tank and the license plate number and would also have some added methods. Instead of repeating the definitions of the instance variables and methods of the class of vehicles within the class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access