Question 4-3

Consider the following two class definitions.

class Test {
  public int a;
  public Test() {
    a = 8;
  }
  public Test(int x) {
    a = x + 4;
  }
}
class Example extends Test {
  public int b;
  public Example() {
    b = 0;
  }
  public Example(int y) {
    super(y + 2);
    b = 1;
  }
}
What will the following sequence of statements print?
Example foo = new Example();
IO.println(foo.a);
IO.println(foo.b);
Example bar = new Example(8);
IO.println(bar.a);
IO.println(bar.b);

Solution


8
0
14
1

Back to Review for Quiz 4