+ 4
Can anyone explain-- Can we return a value in a Constructor...??
If yes then please explain with example.... if no then why??
6 Answers
+ 4
noway, we are not suppose to return in constructor.
Because this method helps to initialize the class members, so what's the point of returning the value from it. Also consider this example
test obj = new test ();
Assume, if you are returning from constructor, where it will be stored. Because obj is meant to hold the class object not any other value.
Hope you're clear now
+ 2
Note: Constructor is called when class is instantiated.
+ 1
Well constructor can never return a value.
There is no return type also not even void.
0
No. Constructors are initializers. They, by definition, cannot return a value. Additionally, the lesson explicitly stated constructors cannot return a value.
0
Constructor is built for SETTING the started value. it doesn't need to RETURN something
0
constructor never return value