CoreJava/exp5/PersonDancerDemo.java

33 lines
558 B
Java
Raw Normal View History

2024-05-09 09:10:51 +08:00
package exp5;
abstract class Person {
public abstract void show();
}
class Dancer extends Person {
@Override
public void show() {
System.out.println("Dancing!!!");
}
}
class PersonTool {
public void method(Person p) {
p.show();
}
}
public class PersonDancerDemo {
public static void main(String[] args) {
PersonTool pd = new PersonTool();
Person p = new Dancer();
pd.method(p);
System.out.println("----------------");
pd.method(new Person() {
@Override
public void show() {
System.out.println("Dancing!!!");
}
});
}
}