A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

class Test6 {
        public static void main(String[] args) {
                new Inter() {
                        public void show() {
                                System.out.println("show");
                        }
                }.show();


                new Person().method(new Inter() {
                        public void show() {
                                System.out.println("show2");
                        }
                });


                new Person().eat().show();
        }
}
interface Inter {
        public void show();
}
class Person implements Inter {
        public void show() {
                System.out.println("show");
        }
        public void method(Inter i) {
                i.show();
                System.out.println("method");
        }
        public Inter eat() {
                return new Inter() {
                        public void show() {
                                System.out.println("eat");
                        }
                };
        }
}

3 个回复

倒序浏览
学习啦!

点评

用了三中情况的调用方法  发表于 2016-3-26 00:10
回复 使用道具 举报
学习了~~~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马