java中能在方法中定义方法吗?

方法中不能直接定义方法,但可以在方法中定义类,类里面再定义方法:
public static void main(String[] args) {
        class A {
void test() {
System.out.println("test()");
}
}
new A().test();
}

猜你喜欢

转载自blog.csdn.net/weixin_39214481/article/details/80366886