小编Mer*_*ack的帖子

在 Java 中,“this”在继承该方法的子类上调用的超类方法中表示什么?

代码是这样的:

class Main {  
  public static void main(String args[]) { 
        Person p1 = new Student();
        Person p3 = new Teacher();
        Student p4 = new Student();
        OnlineLecture lec3 = new OnlineLecture();
        
        lec3.addAttendant(p1);
        lec3.addAttendant(p3);
        lec3.addAttendant(p4);
  }
}


abstract class Person {
    public void join(Lecture lec) { 
        System.out.println("Joining "+lec);
    }
    public void join(OnlineLecture lec) {
        System.out.println("Joining "+lec);
    }
}

class Student extends Person {
    public void join(Lecture lec) {
        System.out.println("Student joining "+lec);
    }
}

class Teacher extends Person {
    public void join(OnlineLecture lec) …
Run Code Online (Sandbox Code Playgroud)

java subclass this superclass

6
推荐指数
1
解决办法
115
查看次数

标签 统计

java ×1

subclass ×1

superclass ×1

this ×1