日期:2014-05-20  浏览次数:20773 次

如何用一个方法同时显示两种构造方法
public   class   people   {
        String   peopleName;
        int   peopleNum;

        public   people()   {//构造方法1
                peopleName= "   zouruixin ";
                peopleNum   =   23;
        }
        public   people(String   peopleName1,int   peopleNum1){//构造方法2
                peopleName=peopleName1;
                peopleNum=peopleNum1;
        }
如何通过一种方法同时调用两种构造方法啊

------解决方案--------------------
public class people {
String peopleName;
int peopleNum;

public people() {//构造方法1
peopleName= " zouruixin ";
peopleNum = 23;
}
public people(String peopleName1,int peopleNum1){//构造方法2
this();
peopleName=peopleName1;
peopleNum=peopleNum1;
}
}
这样调用第二个方法时就也调用第一个了