+ 2

Can we override constructor in java or in any language!!

6th Dec 2017, 5:58 AM
Hemant Dhiman
Hemant Dhiman - avatar
14 ответов
+ 4
@Baptiste Isn't overriding in Java similar to the virtual functions in C++? If yes, how are virtual constructors valid? I thought you couldn't make any... https://stackoverflow.com/questions/733360/why-do-we-not-have-a-virtual-constructor-in-c
6th Dec 2017, 6:34 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
As you can write it without parameter, I thought no, but it must be a misconception on my side
6th Dec 2017, 10:26 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 4
@~swim~ Thats why I used the term similar, not same. And yes, thanks for pointing out the differences! I really got to know a lot more about this today.
6th Dec 2017, 1:07 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
In C++ and python you can. I think C# also I do not know for Java though but I think you can
6th Dec 2017, 6:12 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
Hum, I did not think of overriding this way but yes you are right I thought of it as overriding the default one there is when you do not make it yourself
6th Dec 2017, 7:05 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
@Baptiste Isn't that 'overloading' ?
6th Dec 2017, 8:48 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
can't override in java
6th Dec 2017, 6:19 AM
Saurabh Suman
Saurabh Suman - avatar
0
why? explanation??
6th Dec 2017, 6:20 AM
Hemant Dhiman
Hemant Dhiman - avatar
0
Constructor looks like a method but name should be as class name and no return value.
6th Dec 2017, 6:24 AM
Saurabh Suman
Saurabh Suman - avatar