测试类。。。重写篇
package com.c2; public class Ext { public static void main(String[] args) { Student s = new Student(); System.out.println(s.name); System.out.println(s.age); } } package com.c2; public class Person { int age; String name = "zhangsan"; Person() { } public Person(int a) { age = a; } } package com.c2; public class Student extends Person { public Student() { } public Student(int a) { super(23); } }
总结:构造函数必须带着,重写发生在子类继承父类里,继承是子类调用父类的属性或方法,重写时方法名称,及参数列表都得相同,但方法体内容不相同,super关键字是调用父类里的方法