Chapter 9 Quiz Flashcards
Every class in Java, except ________, extends an existing.
Objects
Which superclass members are inherited by all subclasses of that superclass?
a. private instance variables and methods.
b. protected instance variables and methods.
c. private constructors.
d. protected constructors.
b. protected instance variables and methods.
Using the protected keyword gives a member:
private access
package access
block scope
public access
package access
Overriding a method differs from overloading a method because:
Overridden methods have the same signature
Superclass methods with this level of access cannot be called from subclasses
Private
The default implementation of method clone of Object performs a ________.
shallow copy
When a subclass constructor calls its superclass constructor, what happens if the superclass’s constructor does not assign a value to an instance variable?
The program compiles and runs because the instance variables are initialized to their default values
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?
super
Inheritance is also known as the _______
a. knows-a relationship.
b. has-a relationship.
c. uses-a relationship.
d. is-a relationship.
d. Inheritance is known as the is-a relationship.
Which of the following is not a superclass/subclass relationship?
a. Employee/Hourly Employee.
b. Vehicle/Car.
c. Sailboat/Tugboat.
d. None of the above.
c. Sailboat/Tugboat (they are both different type of boats, they would both be subclasses of superclass boat.)
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?
a. base.
b. this.
c. public.
d. super.
d. super (must be called in the default constructor of the subclass)
Superclass methods with this level of access cannot be called from subclasses.
a. private.
b. public.
c. protected.
d. package.
a. Private level access
private fields of a superclass can be accessed in a subclass
a. by calling private methods declared in the superclass.
b. by calling public or protected methods declared in the superclass.
c. directly.
d. All of the above.
b. By calling public or protected methods in the super class.
When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________.
a. a compile-time error.
b. a syntax error.
c. infinite recursion.
d. a runtime error.
c. Infinite Recursion
A form of software reuse in which existing classes acquire the member of existing classes and embellish those classes with new capabilities.
Inheritance