33 lines
558 B
Java
33 lines
558 B
Java
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!!!");
|
|
}
|
|
});
|
|
}
|
|
} |