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
时间: 2024-10-21 06:28:56