默认情况下,类构造函数是否为空? [英] Are class constructors void by default?
本文介绍了默认情况下,类构造函数是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在阅读C#中的类构造函数.示例显示了重载的类构造函数.而且它们都没有void
关键字,也没有返回值..
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..
例如
public Class myClass
{
public myClass()
{
}
public myClass(int id)
{
}
//other class memeber go here...
}
1)那么说C#构造函数默认为void
是否正确?
1) So is it correct to say C# constructors are void
by default?
2)Java也一样吗?
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
这篇关于默认情况下,类构造函数是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文