Could a main()
method create a Car
object?
Sure, as long as it had access to the class definition.
Car
Object
To see if the design for the class Car
is correct,
let us try to use it in a program.
Here is a short program that uses a Car
object for
calculating miles per gallon:
import Car ; // assume that a class definition is available class MilesPerGallon { public static void main( String[] args ) { Car car = new Car( ______________, ____________, __________ ); System.out.println( "Miles per gallon is " + ______________ ); } }
The program creates an object of the class Car
,
and saves a reference to it in the variable car.