Tag: inner class

为什么内部类可以重写private final方法?

我想知道是否有意义的宣布私有方法是最终的,我认为这是没有意义的。 但我想象中有一种独特的情况,写下代码来搞清楚: public class Boom { private void touchMe() { System.out.println("super::I am not overridable!"); } private class Inner extends Boom { private void touchMe() { super.touchMe(); System.out.println("sub::You suck! I overrided you!"); } } public static void main(String… args) { Boom boom = new Boom(); Boom.Inner inner = boom.new Inner(); inner.touchMe(); } } 它编译和工作。 “我应该touchMe()最后”我以为做到了: public […]