Answered by:
Constructor

Question
-
Is constructor return any value internally ?
This question answer actually i know constructor never return any value but one of my friend argue that constructor returning value internally if it correct plz explain me .
If yes then explain me what value and what time it returning?
S.K Nayak
Answers
-
Hi,
It has been ask before.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by RJP1973 Monday, January 5, 2015 11:05 AM
- Marked as answer by SURYA KANT NAYAK Monday, January 12, 2015 10:32 AM
All replies
-
Hi,
It has been ask before.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by RJP1973 Monday, January 5, 2015 11:05 AM
- Marked as answer by SURYA KANT NAYAK Monday, January 12, 2015 10:32 AM
-
-
-
The answers above may appear to be contradictory, but this is just because constructors are a bit of a special case!
In an attempt to clarify:
Nirosha is correct in that you never actually specify a return type in a constructor yourself. Constructors are always declared with no return type, unlike other methods (see C# classes for example of a class definition with a couple of constructors and one standard method).
However, as Magnus says, constructors implicitly (i.e. "secretly") always return the object that has just been created, which is why you should never (and can't) actually specify a return type yourself.
Hope that helps.
-
The constructor is that the runtime uses type data generated by the compiler to determine how much space is needed to store an object instance in memory, be it on the stack or on the heap. This space includes all members variables and the vtbl. After this space is allocated, the constructor is called as an internal part of the instantiation and initialization process to initialize the contents of the fields.
- Proposed as answer by Ammar.Zaied Monday, January 5, 2015 1:18 PM