示例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中构造函数的名称与类名相同?的详细内容。
