题目:编写具有两个构造器的类,并且在第一个构造器中调用第二个构造器。
分析:在类中通过this调用构造器有很多需要遵守的规则
- 不能调用两个构造器
- 必须将构造器调用置于方法的起始位置
- 禁止在除构造器的其他地方调用构造器
public class test { public test(){this("default");} public test(String s){System.out.println(s);} public static void main(String[] args) { test t=new test(); } }