0

Does constructor return any value?

java

18th Jul 2018, 6:34 AM
Md Tarique Aziz
6 Antworten
+ 7
Ipang, thank you very very much. I will read it
18th Jul 2018, 9:39 AM
Dmitry
Dmitry - avatar
+ 6
Ipang, I agree with you. But I have seen the right answer in quiz here is that constructor returns value. I'm confused about this.
18th Jul 2018, 8:05 AM
Dmitry
Dmitry - avatar
+ 6
Ipang, certainly. If I have see it again, I will share it here
18th Jul 2018, 10:02 AM
Dmitry
Dmitry - avatar
+ 3
Dmitry I myself am still uncertain, but I was thinking the 'new' operator is responsible for instantiating an new object, and the constructor is then invoked behind the scenes to setup the new object's members values. Perhaps these links can explain better : ) https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html https://stackoverflow.com/questions/14737420/what-does-a-constructor-return-in-java
18th Jul 2018, 9:38 AM
Ipang
+ 2
To my understanding constructors are used to initialize/prepare a class instance's members on creation/instantiation, setting a predefined/default values for the members, so I guess it doesn't return anything, and the constructor doesn't use 'return' statement either, which also indicated that nothing was returned, but I could be wrong : ) Hth, cmiiw
18th Jul 2018, 7:53 AM
Ipang
+ 1
Dmitry No problem mate, btw can you please take a screenshot of the quiz and the correct answer, where it says constructors can return something, I begin to doubt the quiz a little. Thanks : )
18th Jul 2018, 9:46 AM
Ipang