您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

为什么Java中构造函数的名称与类名相同?

2024/4/1 6:40:22发布18次查看
每个类对象都是使用相同的new关键字创建的,因此它必须具有关于必须创建对象的类的信息。因此,构造函数的名称应与类名相同。
示例class myconstructor{ public myconstructor() { system.out.println("the constructor name should be same as the class name"); } public static void main(string args[]){ myconstructor mc = new myconstructor(); }}
在上面的程序中,构造函数的名称应该与类名相同(myconstructor)。
输出the constructor name should be same as the class name
以上就是为什么java中构造函数的名称与类名相同?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product