- class a85 {
- public static void main(String[] args) {
- Son s1 = new Son();
- System.out.println(s1.getName() + "..." + s1.getAge());
- }
- }
- class Father {
- private String name;
- private int age;
- public Father() {
- System.out.println("Father 空参构造");
- }
- public Father(String name,int age) {
- this.name = name;
- this.age = age;
- System.out.println("Father 有参构造");
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public int getAge() {
- return age;
- }
- }
- class Son extends Father {
- public Son() {
- this("王五",25);
- System.out.println("Son 空参构造");
- }
- /*public Son(String name,int age) { //有参构造
- super(name,age);
- System.out.println("Son 有参构造");
- }*/
- }
复制代码
|