猜猜这里的代码输出的结果是多少?

 

package test;
public class ConstructorExample {
    static class Foo {
        int i;

        Foo() {
            i = 1;
            int x = getValue();
            System.out.println(x);
        }

        protected int getValue() {
            return i;
        }
    }

    static class Bar extends Foo {
        int j;

        Bar() {
            j = 2;
        }

        @Override
        protected int getValue() {
            return j;
        }
    }

    public static void main(String[] args) {
        Bar bar = new Bar();
    }
}

 

java中的虚函数表的引用,竟让在对象的构造函数执行之前就已经被关联到对象了??跪了

相关文章:

  • 2021-05-27
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-07-26
  • 2021-11-10
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
相关资源
相似解决方案