Post date: Sep 25, 2017 10:8:21 AM
Chapter 7: Inheritance
7.2 Encapsulation and Inheritance
7.3 Programming with inheritance
Suggested Self-Test Exercises:
p495-6: 14-17
p502-3: 18-22
Lab Exercises:
p508-9: Ex 1
p509: Ex 2
p511-12: Ex 6, 7
In-Class Exercises:
p511-12: Ex 6
Create a class called Vehicle that has the manufacturer’s name (type String), number of cylinders in the engine (type int), and owner (type Person given next). Then, create a class called Truck that is derived from Vehicle and has the following additional properties: the load capacity in tons (type double since it may contain a fractional part) and towing capacity in pounds (type int). Be sure your class has a reasonable complement of constructors, accessor and mutator methods, and suitably defined equals and toString methods. Write a program to test all your methods.
The definition of the class Person follows. Completing the definitions of the methods is part of this programming project.
public class Person
{
private String name;
public Person()
{...}
public Person(String theName)
{...}
public Person(Person theObject)
{...}
public String getName()
{...}
public void setName(String theName)
{...}
public String toString()
{...}
public boolean equals(Object other)
{...}
}