JAVA---抽象类的匿名子类

package exer;


public class Exer {
	public static void main(String[] args) {
		Person p=new Person(){
			public void show(){
				System.out.println("这是匿名类非匿名对象");
			}
		};
		method(p);
		System.out.println("************************");
		method(new Person(){
			public void show(){
				System.out.println("这是匿名类匿名对象");
			}
		});
	}
	public static void method(Person p){
		p.show();
	}
}
abstract class Person{
	String name;
	public Person(){
		
	}
	public abstract void show();
}

posted @ 2022-01-26 17:49  ice--cream  阅读(43)  评论(0编辑  收藏  举报