Chapter 10 - Part 2
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC
ClassB
In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC
ClassC
T/F: In an inheritance relationship, the subclass constructor always executes before the superclass constructor.
False
T/F: Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.
False
In the following code, which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public final int method2(double b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public int method2(double c){} Line 12 }
Line 11
In the following code, which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 }
Line 4
In the following code, which line in ClassA has an error? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodA(double) { } Line 10 }
Line 8
T/F: It is not possible for a superclass to call a subclass's method.
True
In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.
a UML diagram
Protected class members can be denoted in a UML diagram with the ________ symbol.
#
In a class hierarchy ________.
the more general classes are toward the top of the tree and the more specialized classes are toward the bottom
In an inheritance relationship ________.
the superclass constructor always executes before the subclass constructor
In the following code, what is missing from ClassA? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodB(double) { } Line 10 }
It does not override methodA.
In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement "+ "in the constructor."); } }
It will call the constructor of ClassA that receives an integer as an argument.
In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.
polymorphic
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
ClassA