X hits on this document

120 views

0 shares

0 downloads

0 comments

21 / 46

© S. Uchitel, 2004

21

Constructors: Example

Suppose the Car class has three constructors:

Car(); //Creates a black Ford T-model

Car(String c); // Creates a Ford T-model with

// coloured according to parameter

Car(String colour, String model);  

// Creates car with colour

and model according to parameters

Car MyFirstCar, MySpareCar, MyOtherCar;

myFirstCar = new Car();

mySpareCar = new Car(“blue”);

myOtherCar = new Car(“red”, “testarossa”);

Hence, cars can be built in three different ways.

Document info
Document views120
Page views120
Page last viewedFri Dec 09 11:39:09 UTC 2016
Pages46
Paragraphs816
Words2901

Comments