标签:static lang int rgs 抽象 public abstract override 实现
// Father.java
public abstract class Father {
public abstract void say();
}
// Say.java
public class Say {
public void say(Father father){
father.say();
}
}
// Client.java
public class Client {
public static void main(String[] args) {
Say say = new Say();
say.say(new Father() {
@Override
public void say() {
System.out.println("I am the father.");
}
});
}
}
// Father.java Here is the change
public interface Father {
void say();
}
// Say.java
public class Say {
public void say(Father father){
father.say();
}
}
// Client.java
public class Client {
public static void main(String[] args) {
Say say = new Say();
say.say(new Father() { // @Override is not allowed in implement
public void say() {
System.out.println("Hi, this is Tom.");
}
});
}
}
标签:static lang int rgs 抽象 public abstract override 实现
原文地址:https://www.cnblogs.com/nedrain/p/13260066.html