ICSI 213: chapter 10 - inheritance (interface and polymorphism)
If a subclass constructor does not explicitly call a superclass constructor
Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes
In an inheritance relationship
The superclass constructor always executes before the subclass constructor
In UML diagrams, inheritance is shown
With a line that has an open arrowhead at one end that points to the superclass
If a class contains an abstract method
You cannot create an instance of the class, the method will have only a header, but not a body, and end with a semicolon and the method must be overridden in subclasses
If ClassC extends ClassB, which extends ClassA, this would be an example of
a chain of inheritance
When an "is a" relationship exists between objects, it means that the specialized object has
all the characteristics of the general object, plus additional characteristics
All fields declared in an interface
are final and static
Like a family tree, a ________ shows the inheritance relationship between classes
class hierarchy
An anonymous inner class must
implement an interface or extend another class
In a class hierarchy:
the more general classes are toward the top of the tree and the more specialized are toward the bottom
If a superclass does not have a default constructor or a no-arg constructor
then a class that inherits from it, must call one of the constructors that the superclass does have
What is required for an interface method that has a body
The method header must begin with the key word default
If you do not provide an access specifier for a class member, the class member is given ________ by default.
package
A subclass may call an overridden superclass method by
prefixing its name with the super key word and a dot (.)
Which of the following is TRUE about protected access? A) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package. B) Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package. C) Protected members cannot be accessed by methods in any other classes. D) Protected members are actually named constants.
A) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package
When a subclass overloads a superclass method:
Both methods may be called with a subclass object
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
ClassA
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
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method
FALSE
If two methods in the same class have the same name but different signatures, the second overrides the first.
FALSE
In an inheritance relationship, the subclass constructor always executes before the superclass constructor.
FALSE
Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.
FALSE
When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface.
FALSE
Replacing inadequate superclass methods with more suitable subclass methods is known as what
Method overriding
Protected members are
Not quite private and not quite public
A subclass can directly access
Only public and protected members of the superclass
If ClassA extends ClassB, then
Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
When declaring class data members, it is best to declare them a
private members
In an interface all methods have
public access
Which of the following statements correctly specifies three interfaces
public class ClassA implements Interface1, Interface2, Interface3
Which of the following statements declares Salaried as a subclass of PayType
public class Salaried extends PayType
What key word can you use to call a superclass constructor explicitly
super
When one object is a specialized version of another object, there is this type of relationship between them
"is a"
Protected class members are denoted in a UML diagram with the symbol
#
This annotation tells the Java compiler that a method is meant to override a method in the superclass
@Override
All methods in an abstract class must also be declared abstract
FALSE
An abstract class is not instantiated, but serves as a superclass for other classes
TRUE
Every class has a toString method and an equals method inherited from the Object class.
TRUE
Every class is either directly or indirectly derived from the Object class
TRUE
It is not possible for a superclass to call a subclass's method
TRUE
Private members of the superclass cannot be accessed by the subclass
TRUE
When a subclass extends a superclass, the public members of the superclass become public members of the subclass
TRUE
When a method is declared with the ________ modifier, it cannot be overridden in a subclass
final
A protected member of a class may be directly accessed by
methods of the same class, methods of a subclass, and methods in the same package
The super statement that calls the superclass constructor
must be the first statement in the subclass's constructor
If two methods have the same name but different signatures, they are
overloaded
If a class contains an abstract method
The method will have only a header, but not a body, and end with a semicolon