抽象類:匿名物件匿名類
阿新 • • 發佈:2021-01-28
public class helloworld{
public static void main(String[] args){
man man1 = new man();//非匿名類的非匿名物件
cite(man1);
cite(new man());//非匿名類的的匿名物件
person person1 = new person() {
@Override
public void eat() {
System.out.println("吃吃吃1" );
}
};
cite(person1);//匿名類的非匿名物件
cite(new person() {//匿名類匿名物件(後加的)
@Override
public void eat() {
System.out.println("吃吃吃1");
}
};)
}
public static void cite(person p){
p.eat();
}
}
abstract class person{
abstract public void eat();
}
class man extends person{
public void eat(){
System.out.println("吃吃吃");
}
}
輸出: