java new类名后接方法名声明
2014-12-10 17:34 briller 阅读(716) 评论(0) 编辑 收藏 举报public class TestBase { int x = 3; public void ppp() { System.out.println(x + 4); }
} public class TestMain { public static void main(String[] args) { TestBase t = new TestBase() { public void ppp(){ System.out.println(x + 5); } }; t.ppp(); } }
相当于新建一个继承自TestBase的匿名类(如果没理解错的话) 输出的是8