package com.company;
public class AnoymousInner {
public void test (Device d)
{
System.out.println("购买了一个"+d.getName()+"共花费了"+d.getPrice() );
}
public static void main(String [] args)
{
AnoymousInner ai = new AnoymousInner();
ai.test(new Device() {
@Override
public double getPrice() {
return 56.78;
}
});
}
Device d = new Device() {
{
System.out.println("匿名内部类的初始化块 ");
}
@Override
public double getPrice() {
return 56.2;
}
public String getName()
{
return "键盘";
}
};
}
abstract class Device
{
private String name;
public abstract double getPrice();
public void Device(){};
public String getName(){return " ";};
public void Device(String name){}; //这就是抽象方法
}