我有4节课。一个是驱动类,一个是接口类和两个子类。这是接口类:
public interface Speaker {
public void speak();
public void announce(String announcement);
}
这是驱动程序类:
public abstract class SpeakerDriver implements Speaker {
public static void main (String [] args) {
Speaker ref;
Politician poli = new Politician("George Bush");
Lecturer lect = new Lecturer("Professor Cross");
Pastor past = new Pastor ("P.M. Smith");
ref = poli;
ref = lect;
ref = past;
System.out.println();
System.out.println(lect);
System.out.println(past);
}
}
这些是两个子类:
public class Pastor implements Speaker {
protected String announcement;
public Pastor (String name) {
}
@Override
public void speak() {
}
@Override
public void announce(String announc) {
System.out.println("I am the pastor at CCBC.");
}
}
public class Lecturer implements Speaker {
protected String announcement;
public Lecturer(String name) {
}
@Override
public void speak() {
}
@Override
public void announce(String announcement) {
System.out.println("I am the lecturer at CCBC");
}
}
我的问题是,我的实现有什么问题使输出看起来像这样:
讲师@a90653 牧师@de6ced
当它们应该包含 println 中的文本时。