| 本帖最后由 李盈科 于 2012-1-3 17:25 编辑 
 cont应该就是要用Contents的匿名内部类重写 value()方法 从而得到 i 的值,我对代码进行了补全,你参考一下吧,刚才写错了。
 复制代码interface Contents{
        public int value();
}
class Good
{
        public Contents cont()
        {
                return new Contents()
                {
                        private int i = 11;
                        public int value()
                        {
                                return i;
                        }
                };
        }
        public static void main(String[] args)
        {
                
                        Good good = new Good();
                        
                        System.out.println(good.cont().value());
                
        }
}
 |