本帖最后由 smallfoxxizo 于 2014-01-19 21:57:26 编辑

解决方案 »

  1.   

    多态么,
    Subclass me = new Subclass();相当于Super me = new Subclass();new子类当然要初始化他的父类了,又其父才有其子么!
      

  2.   

    你把修饰符给去掉了我操,这算是重写方法吗,你调用的还是继承上从父类继承的方法。不信你debug一下。
      

  3.   

     /**
         * Returns the runtime class of this {@code Object}. The returned
         * {@code Class} object is the object that is locked by {@code
         * static synchronized} methods of the represented class.
         *
         * <p><b>The actual result type is {@code Class<? extends |X|>}
         * where {@code |X|} is the erasure of the static type of the
         * expression on which {@code getClass} is called.</b> For
         * example, no cast is required in this code fragment:</p>
         *
         * <p>
         * {@code Number n = 0;                             }<br>
         * {@code Class<? extends Number> c = n.getClass(); }
         * </p>
         *
         * @return The {@code Class} object that represents the runtime
         *         class of this object.
         * @see    Class Literals, section 15.8.2 of
         *         <cite>The Java&trade; Language Specification</cite>.
         */
        public final native Class<?> getClass();明白了?
      

  4.   


    这个我也知道,我就是不清楚那个引用类型是什么时候从子类变成父类的?
    那就应该研究extends的内部机制了,不过这个在源码中不知道还有没有。
      

  5.   

    这个还真是不好翻译,只是大体明白怎么回事返回当前对象的运行时类,返回的类为:所对应类的static synchronized方法锁定的那个类(这个可能涉及到Java对象方法的调用机制,不看Java标准是解释不了的)。The actual result type is {@code Class<? extends |X|>} where {@code |X|} is the erasure of the static type of the expression on which {@code getClass} is called.
    结果就是继承自|X|的某个类,而|X|就是getClass方法在哪个类中被调用的,结果其实就是返回该对象的最远代子类,其实也就是重载了。就相当于你调用父类的toString()会调子类的toString()一样。第一次调用getClass是me.exampleMethod(),虽然Subclass没有exampleMethod是继承来的,但是,你是用的显示调用,就是在Subclass中调用的,没问题;而第二次调用,虽然你是调用的Supeclass但是,返回的仍然是继承类的重载方法
      

  6.   

    用debug模式跟踪一下,一切都会明白的
      

  7.   

    差点没看到
    SuprClass里的interestingMethod方法是private(那么Subclass里interestingMethod方法并没有覆盖父类)
    所以在执行的interestingMethod方法的时候用的是invokeespecial指令
    就不会再根据栈顶的实际类型来选在方法接受者了,也就执行不到子类的interestingMethod