Inheritance - Using super QuizS2C Home « Inheritance - Using super Quiz

OO Concepts Quiz 7

The quiz below tests your knowledge of the material learnt in OO Concepts - Lesson 7 - Inheritance - Using super.

Question 1 : We can explicitly code super() to access what?
- We can explicitly code <code>super()</code> to access <code>superclass</code> constructors.
Question 2 : We access members of the superclass above a subclass using the extends keyword?
- We access members of the <i>superclass</i> above a <i>subclass</i> using the <code>super()</code> keyword.
Question 3 : What happens in a subclass when the superclass has just a one argument constructor and an implicit call to super() is supplied by the compiler?
- We got a compiler error because the implicit call to <code>super()</code> supplied by the compiler didn't find a match.
Question 4 : We can access instance variables in a superclass using the super keyword along with their identifer?
- We CAN access instance variables in a <i>superclass</i> using their identifer along with the <code>super()</code> keyword.
Question 5 : What is output from the following code snippet?
package info.java8;
public class S {
    int i = 1;
    S() {
        System.out.print("i = " + 1);
    }
}
package info.java8;
public class T extends S{
    int i = 2;
    T() {
        System.out.print(this.i);
        System.out.print("i = " + super.i);
    }
    public static void main(String[] args) {
        T t = new T();
    }
}
- The code will compile and output <code>i = 12i = 1</code> via implicit call to <code>super()</code> and output from the <code>T</code> constructor.
Question 6 : When explicitly coding super() it must be the first statement within the constructor or we get a compiler error?
- When explicitly coding <code>super()</code> it MUST BE the first statement within the constructor or we get a compiler error.
Question 7 : What is output from the following code snippet?

package info.java8;
public class S {
    int i = 1;
    public static void main(String[] args) {
        S s = new S(1);
    }
    S() {
        System.out.print("i = " + 1);
    }
    S(int i) {
        super();
        this();
        System.out.print("i = " + 1);
    }
}
- The code won't compile as we cannot use <code>super()</code> and <code>this()</code> together.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge of abstraction.