I have been reading on class constructors in C#. Examples are showing overloaded class contructors. And all of them do not have a void keyword and neither they have a return value..
e.g.
public Class myClass
{
public myClass()
{
}
public myClass(int id)
{
}
//other class memeber go here...
}
1) So is it correct to say C# constructors are void by default?
2) Does the same applies to Java as well?
no, they are constructors, if anything, you can think of them as returning an object of the class they are from. But, they aren't normal method/functions
No Constructors implicitly return class type same as java also.
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