//创建类的匿名抽象类的匿名子类
public class PersonTest {
public static void main(String[] args) {
PersonTest pp = new PersonTest();
//非抽象类的非匿名子类
Student s1 = new Student();
pp.method(s1);
//非抽象类的匿名子类
pp.method(new Student());
//抽象类的非匿名子类
Person p1 = new Person() {
@Override
public void eat() {
// TODO Auto-generated method stub
}
@Override
public void breath() {
// TODO Auto-generated method stub
}
}
//抽象类的匿名子类
pp.method(new Person() {
@Override
public void eat() {
// TODO Auto-generated method stub
}
@Override
public void breath() {
// TODO Auto-generated method stub
}
});
}
public void method(Person p) {
p.eat();
p.breath();
}
}
abstract class Creature{
public abstract void breath();
}
abstract class Person extends Creature{
String name;
int age;
public Person() {
super();
}
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
public abstract void eat();
public void work() {
System.out.println("认真工作");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Student extends Person{
// public Student() {
//
// }
@Override
public void eat() {
// TODO Auto-generated method stub
}
@Override
public void breath() {
// TODO Auto-generated method stub
}
}