super 和this

class Person{
    protected String name;
    

    public Person(String name) {
        this.name = name;
    }

}

class Student extends Person{
    private String name;

    public Student(String name, String name1) {
        super(name);
        this.name = name1;
    }

    public void getInfo(){
        System.out.println(this.name);      //Child
        System.out.println(super.name);     //Father
    }

}

public class Test {
    public static void main(String[] args) {
        Student s1 = new Student("Father","Child");
        s1.getInfo();

    }
}

  

Child
Father

  

posted @ 2022-08-01 16:28  11111ghm  阅读(15)  评论(0)    收藏  举报