English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2006-08-18 05:51:31 · 3 answers · asked by vipul 1 in Computers & Internet Programming & Design

3 answers

a constructor is used to instantiate an object - there is nothing for it to return.

think of how a constructor is used:
assume a constructor for a car object:

Car mySportsCar = new Car();

Now the variable mySportsCar is an object of type car. This was the point of the constructor.

mySportsCar can now access the public methods to the Car object to define itself.

You can have overloaded constructors to help instantiate the car for example:
Car mySportsCar = new Car("SportsCar");

the above statement would require your car object to have a constructor that accepts a string.
Based on this string you can set default values for your car, maybe sportscar defaults to two doors;

But you still don't need to return this information, the mySporstCar variable is INSTANTIATED with the information.

2006-08-18 06:00:35 · answer #1 · answered by Anonymous · 0 0

The constructor is used to to initialize object, so it does not have any return type.. only member functions have return types..

thanks

2006-08-18 14:14:20 · answer #2 · answered by yaramala 2 · 0 0

Ummm, you should repost your question with good grammar.

2006-08-18 13:01:04 · answer #3 · answered by Yoi_55 7 · 0 0

fedest.com, questions and answers