本帖最后由 黑马-王鹏 于 2013-3-13 21:04 编辑
- class Person
- {
- private String name;
- private int age;
- {
- System.out.println("年龄");
- }
- Person()
- {
- System.out.println("姓名");
- }
- Person(String name)
- {
- this();
- this.name =name;
- }
- Person(String name,int age)
- {
- this(name);//<STRONG><FONT color=red>this调用构造函数必须放在第一行。因为初始化要先执行</FONT></STRONG>
- this.age = age;
- }
- }
- class PersonDemo4
- {
- public static void main(String[] args)
- {
- Person p = new Person("lisi",30);
- }
- }
复制代码 file:///C:/Documents%20and%20Settings/wangpeng/Application%20Data/Tencent/Users/1198571320/QQ/WinTemp/RichOle/D6QO]@PMSHAY2N4Q2)]R~M0.jpg
我个人理解应该是姓名在前,年龄在后,为什么反了呢?
|
|