- class Test_Teacher {
- public static void main(String[] args) {
- EnglishTeacher t1 = new EnglishTeacher();
-
- System.out.println(t1.age+"..."+t1.salary);
- }
- }
- class Teacher {
- public int salary ; //父类成员变量
- }
- class EnglishTeacher extends Teacher {
- public int age ; //子类成员变量
- public EnglishTeacher(){
- this.age = 30; //调用this
- super.salary = 3000; //调用super
- }
- }
复制代码
今天老师说,this和super关键字不能同时出现在构造方法中,经过验证,
this和super关键字可以出现在子类构造方法里边,只是不能同时调用构造方法而已 |
|