Review Questions

6.9 Given the following code, which of these constructors can be added to MySubclass without causing a compile-time error?
class MySuper {
    int number;
    MySuper(int i) { number = i; }
}

class MySub extends MySuper {
    int count;
    MySub(int cnt, int num) {
        super(num);
        count=cnt;
    }

    // INSERT ADDITIONAL CONSTRUCTOR HERE
}

Select the one correct answer.

  1. MySub() {}

  2. MySub(int cnt) { count = cnt; }

  3. MySub(int cnt) { super(); count = cnt; }

  4. MySub(int cnt) { count = cnt; super(cnt); }

  5. MySub(int cnt) { this(cnt, cnt); }

  6. MySub(int cnt) { super(cnt); this(cnt, 0); }

6.10 Which statement is true?

Select the one correct answer.

  1. A super() or this() call ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.