Why constructors don't have return type?

Questions by ratna_ponnapalli   answers by ratna_ponnapalli

Showing Answers 1 - 5 of 5 Answers

nandha gopal

  • Apr 13th, 2006
 

The constructor is getting called when ever the object for the class is created.In java or c++  the object is created like as follows

class A

{

//some code

}//class ends

in java   A obj = new A();

in c++ A obj;    .

giving return type for a constructor is an syntax error.

There is no place holder for capturing the return value.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions