/**
* @author Administrator
*本例意在说明如果一个类里定义了构造函数,则系统不会再给定义默认的无参构造函数
*/
public class Rock {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.err.println(new Rock());
}
* @author Administrator
*本例意在说明如果一个类里定义了构造函数,则系统不会再给定义默认的无参构造函数
*/
public class Rock {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.err.println(new Rock());
}
}
上述代码为正确代码
********************************************************************
public class Rock {
public Rock(int i){
System.err.println(i);
}
public static void main(String[] args) {
System.err.println(new Rock()); // 因类中定义了构造函数导致默认构造函数 不存在
}
}
********************************************************************
如果一个类里定义了构造函数,则系统不会再给定义默认的无参构造函数。如若还需要无参的构造函数,则必须显式的在类中定义。