Java学习

public class Today {

String name;
    int age;
    int weight;
    int height;

	public Today(){//无参构造器  默认会有
        
    }	

		public Today(String name){//有参构造器  ----> 方法重载 
        	this.name = 'Joh'
    }	

    }

}

/*

!!当你自己在类方法中写构造器方法时候,如果你定义了有参构造器,但是你在new对象的时候你并没有使用有参构造那么,你必须把你的无参构造器显式的写出来,也就是你待new的类中有参以及无参构造都必须存在!!

*/

posted @ 2024-06-27 15:56  RoeInCQUPT  阅读(9)  评论(0)    收藏  举报