package yuwei.com;
interface Product{
int getPrice();
String getName();
}
abstract class ProductTwo{
private String name;
private int Price;
public abstract int getPrice();
public String getName()
{
return this.name;
}
public ProductTwo() {}
public ProductTwo(String name) {
this.name = name;
}
}
class AnonymousClass{
public void test(Product p) {
System.out.println("Price:"+p.getPrice() + "\tName:" + p.getName());
}
public void test1(ProductTwo p) {
System.out.println("Price:"+p.getPrice() + "\tName:" + p.getName());
}
}
public class AnonymousClassDemo {
public static void main(String[] args) {
AnonymousClass A = new AnonymousClass();
A.test(new Product()
{
public int getPrice() {
return 10;
}
public String getName() {
return "AAAAAA";
}
});
System.out.println("********************");
A.test1(new ProductTwo()
{
public int getPrice() {
return 23;
}
public String getName() {
return "AD钙";
}
});
System.out.println("********************");
A.test1(new ProductTwo("蒙牛")
{
public int getPrice() {
return 98;
}
});
}
}