Answer:
Is the Car class
made up of smaller software objects?
- No. It consists of some primitive (non-object) data and one method.
What are the instance variables of class Car?
- startMiles
- endMiles
- gallons
What is the method of class Car?
- calculateMPG()
Holding the State of an Object
The state of an object consists of the values held by its instance variables.
These may change during the lifetime of the object.
Here is a main() program that constructs a Car
object.
class MpgTester
{
public static void main ( String[] args )
{
Car myCar = new Car( 12000, 12340, 12.3 );
. . . . . .
}
}
When the object is constructed, its state is initialized to:
- startMiles = 12000
- endMiles = 12340
- gallons = 12.3
The object referenced by myCar holds these values
as long as it exists.
QUESTION 3:
Could a collection of several cars be regarded as an object?