+ 4

Can anyone explain-- Can we return a value in a Constructor...??

If yes then please explain with example.... if no then why??

25th Nov 2016, 7:30 PM
Jenny Lance
Jenny Lance - avatar
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
25th Nov 2016, 7:48 PM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
+ 2
Note: Constructor is called when class is instantiated.
25th Nov 2016, 7:30 PM
Jenny Lance
Jenny Lance - avatar
+ 1
Well constructor can never return a value. There is no return type also not even void.
26th Nov 2016, 1:43 AM
Megatron
Megatron - avatar
0
No. Constructors are initializers. They, by definition, cannot return a value. Additionally, the lesson explicitly stated constructors cannot return a value.
1st Dec 2016, 1:49 PM
David Zimmer
David Zimmer - avatar
0
Constructor is built for SETTING the started value. it doesn't need to RETURN something
5th Jan 2017, 8:50 AM
Nochains
Nochains - avatar
0
constructor never return value
12th Jan 2017, 4:32 AM
Pramod Patil
Pramod Patil - avatar