java 匿名类和匿名方法

package com.test;

interface product{
    
    int getPrice();
}
public class News {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        //直接实例化接口,并实现接口的方法
    int pricene=new product(){
            public int getPrice(){
                
                return 100;
                
            }            
        }.getPrice();

        System.out.println(pricene);
    }



}

参考 http://blog.csdn.net/zhengguanxiong/article/details/52517127

原文地址:https://www.cnblogs.com/tiancai/p/6885293.html