Self-Review Questions

  1. What is the subclass?

  2. What is the superclass?

  3. What does a subclass inherit?

  4. Are constructors inherited by subclasses?

  5. Does Java allow to a supeclass and subclass to have members with the same names?

  6. Explain the differences between super and this in Java

  7. Which methods a subclass cannot override?

  8. What type of inheritance does Java have?
    a)   single inheritance.
    b)   multiple inheritance.
    c)   class inheritance.
    d)   I am not sure.

  9. What restriction is there on using the super reference in a constructor?
    a)   It can only be used in the parent's constructor.
    b)   Only one child class can use it.
    c)   It must be used in the first statement of the constructor.
    d)   none of the above

  10. A class Animal has a subclass Mammal. Which of the following is true:
    a)   Mammal can have no subclasses.
    b)   Mammal can have no other parent than Animal.
    c)   Animal can have only one subclass.
    d)   Mammal can have no siblings.

  11. Consider the following set of Java class definitions:
    class A
    {
       int m1() {return 1;}
       int m2() {return m1();}
       int m4() {return m5();}
       int m5() {return 4;}
    }
    class B extends A
    {
       int m1() {return super.m2();}
       int m3() {return 7;}
    }
    class C extends B
    {
       int m1() {return 2;}
       int m2() {return super.m1();}
       int m3() {return super.m2();}
       int m5() {return 1;}
    }
    class D extends C
    {
       int m1() {return 3;}
       int m2() {return super.m4();}
       int m3() {return super.m3();}
       int m4() {return super.m2();}
    }
    
    What is the output of the call new D().m2()?

    What is the output of the call new D().m3()?

    What is the output of the call new C().m3()?