I was writing code in Java and, absent-minded, i typed at some point public void BaseStation()
as the constructor to a BaseStation
class. To my surprise, this did not cause a compile-time error and the program got to run. Why is that? Is there any reason for someone to have a return type to a constructor?
Specifying a return type makes this a method, rather than a constructor. You can have a method with the same name as the class (though this conflicts the conventions and is bad for readability)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With