Deck 10: Object-Oriented Programming, Part 3: Inheritance, Polymorphism, and Interfaces

Full screen (f)
exit full mode
Question
The extends keyword specifies that the subclass inherits members of the superclass, so:

A) the base class begins with a set of predefined methods and fields inherited from its hierarchy of superclasses.
B) the derived class begins with a set of predefined methods and fields inherited from its hierarchy of superclasses.
C) the derived class begins with a set of predefined methods inherited from its hierarchy of fields.
D) the base class begins with a set of predefined methods inherited from its hierarchy of derived classes.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following would make the subclass Clubs more functional than its superclass Extracurriculars?

A) Define new fields and methods.
B) Create another instance variable (?) that includes intramural sports.
C) Add a variable that identifies whether clubs are available only by students.
D) All of these would make the subclass more functional.
Question
Which of the options listed will happen if the following code segment is run, assuming the remainder of the program is coded correctly?
10 public class Circle extends Figure
11 {
12 private int radius;
13 public Circle( )
14 {
15 super( );
16 radius = 0;

A) The default constructor of the Figure class will be called (line 15).
B) The default constructor of Radius class will set radius to 0.
C) The attempt to instantiate an object of the abstract class will generate a compiler error.
D) All of these are correct.
Question
Why does Java provide a protected access modifier?

A) To hide methods from the client classes
B) To hide fields from client classes
C) So fields and methods can be inherited by subclasses
D) All of these are correct.
Question
An interface can contain one or more abstract methods.
Question
A class must implement at least one interface.
Question
A class can implement more than one interface.
Question
If a class has an abstract method, then that class is automatically an interface.
Question
We can instantiate an object from an interface.
Question
Inheritance is useful for which of the following?

A) It declares the hierarchy of methods that are not common to all classes so they can be reused.
B) It allows superclasses to override subclasses.
C) It allows related classes to be organized into levels of functionality so they can be reused.
D) None of these is correct.
Question
Some OOP developers call a subclass the base class and call a superclass the derived class.
Question
Which of the following are not inherited by subclasses?

A) public fields and public methods
B) private fields and private methods
C) protected fields and protected methods
D) All of these are correct.
Question
Why does Java provide a protected access modifier?

A) To hide methods from the client classes
B) To hide fields from client classes
C) So that fields and methods can be inherited by subclasses
D) All of these are correct.
Question
Why would you want to override a method?

A) It allows you to hide features of the subclass using the super keyword.
B) It allows you to hide features of the superclass that you want to change.
C) It allows you to make the inherited version of the method visible to the client of the subclass.
D) It allows you to invoke the base case method.
Question
The extends keyword specifies that the subclass inherits members of the superclass.
Question
If the call to the direct superclass constructor was not the first statement in the constructor, a compiler error will be generated.
Question
When a class extends another class, the default constructor of the subclass automatically calls the default constructor of the superclass. This is called explicit invocation.
Question
Why does using the protected access modifier compromise encapsulation?

A) Multiple classes can set the value of an instance variable defined in another class.
B) When a class does change a protected value, there is added maintenance complexity.
C) Subclass methods that directly set the value of a protected instance variable need to be verified.
D) When high performance is essential, superclass methods can be used to change the value of protected variables.
Question
Typically, an abstract class is a class that is not completely implemented.
Question
Several classes implement an interface, but all of them implement the same method using the same code. To provide a common method for all of these classes, you would create an abstract class.
Question
The following code will run without errors:
// Figure is an abstract class
Figure f = new Figure( );
Question
Which of the following is true of polymorphism?

A) It simplifies the processing of various elements in the same class hierarchy.
B) To use polymorphism, the classes must be in a different hierarchy.
C) In Greek, the term means "many changes."
D) All of these are correct.
Question
To use polymorphism, the classes must be in a different hierarchy.
Question
Which of the following cannot be an interface member?

A) A class
B) A constant
C) A mutator method
D) An abstract method
Question
An interface can contain one or more static constants.
Question
Which Java keyword do we use in the constructor of a class inheriting from another class if we want to call the constructor of the inherited class?

A) call
B) super
C) constructor
D) clone
Question
Which of the following is correct regarding constructors?

A) Constructors are inherited but cannot be accessed.
B) Constructors are inherited and can be accessed.
C) Constructors are accessible but are not inherited.
D) Constructors are not inherited and cannot be accessed.
Question
An abstract method:

A) has a "do-nothing" body.
B) does not have a body.
C) has a body that operates like any other method.
Question
When is it determined which method is called when using polymorphism?

A) At compile time
B) At the time of writing code
C) At runtime
Question
Which of the following is the correct definition of polymorphism?

A) One form only
B) Two forms only
C) Multiple forms
D) No form
Question
A method in a subclass overriding a method in a superclass cannot call the superclass method.
Question
Overriding a method and overloading a method mean the same thing.
Question
Abstract methods can be static.
Question
Abstract methods can be private.
Question
Abstract methods can be overridden.
Question
A constructor can be declared abstract.
Question
An interface can contain instance variables.
Question
An interface can contain a constructor.
Question
_________ allows us to use the same method call for any object in a class hierarchy.
Question
Which keyword do we use in the header of a class that inherits from another class?

A) inherits
B) extends
C) protected
D) modifies
Question
When class B inherits from class A:

A) A is the superclass and B is the subclass.
B) A is the subclass and B is the superclass.
Question
Assuming that class B inherits from class A and method foo belongs to class A, what do we mean by overriding method foo in class B?

A) We are calling method foo in class B.
B) We are not using method foo in class B.
C) We are replacing the superclass version of the foo method with a new foo method with the same signature.
Question
Assuming that class B inherits from class A, which of the following is correct?

A) An object of class B is an object of class A.
B) An object of class A is an object of class B.
C) An object of class B is an object of class A and an object of class A is an object of class B.
D) None of these is correct.
Question
What keyword do we use in the class header that inherits from an interface?

A) inherits
B) interfaces
C) implements
D) modifies
Question
When a class implements an interface:

A) it does not have to implement the abstract methods of the interface.
B) it has to implement at least one of the abstract methods of the interface, but not all of them.
C) it has to implement all of the abstract methods of the interface.
Question
Private fields and methods are inherited.
Question
Private fields and methods are part of the inheriting class object.
Question
Public fields and methods are inherited.
Question
Protected fields and methods are inherited.
Question
When calling the constructor of a superclass from the constructor of the subclass, the call to that superclass constructor must be the first statement in the subclass constructor.
Question
Typically, an abstract class is a class that is not completely implemented.
Question
Usually, an abstract class contains at least one abstract method.
Question
We can instantiate an object from an abstract class.
Question
If a class has an abstract method, then that class must be declared abstract.
Question
Abstract methods can be called.
Question
Inheritance helps organize related classes into __________.
Question
An abstract class is declared to be abstract by including the __________ keyword in the class header.
Question
The interface concept is Java's way of implementing __________ inheritance.
Question
Because the private instance variables of a class are not inherited, how can the methods of a subclass access the values of these private instance variables?
Question
Suppose you write a program in which you attempt to use a subclass to directly access a private password field in a superclass. Predict what will happen, and suggest a solution that would result in a different outcome.
Question
You have written a SavingsAccount class based on the BankAccount class in the textbook. You wish to instantiate a SavingsAccount object with a starting balance of $2,175.25. Theorize why you would need to provide an overloaded constructor for the SavingsAccount class.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/61
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Object-Oriented Programming, Part 3: Inheritance, Polymorphism, and Interfaces
1
The extends keyword specifies that the subclass inherits members of the superclass, so:

A) the base class begins with a set of predefined methods and fields inherited from its hierarchy of superclasses.
B) the derived class begins with a set of predefined methods and fields inherited from its hierarchy of superclasses.
C) the derived class begins with a set of predefined methods inherited from its hierarchy of fields.
D) the base class begins with a set of predefined methods inherited from its hierarchy of derived classes.
B
2
Which of the following would make the subclass Clubs more functional than its superclass Extracurriculars?

A) Define new fields and methods.
B) Create another instance variable (?) that includes intramural sports.
C) Add a variable that identifies whether clubs are available only by students.
D) All of these would make the subclass more functional.
D
3
Which of the options listed will happen if the following code segment is run, assuming the remainder of the program is coded correctly?
10 public class Circle extends Figure
11 {
12 private int radius;
13 public Circle( )
14 {
15 super( );
16 radius = 0;

A) The default constructor of the Figure class will be called (line 15).
B) The default constructor of Radius class will set radius to 0.
C) The attempt to instantiate an object of the abstract class will generate a compiler error.
D) All of these are correct.
A
4
Why does Java provide a protected access modifier?

A) To hide methods from the client classes
B) To hide fields from client classes
C) So fields and methods can be inherited by subclasses
D) All of these are correct.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
5
An interface can contain one or more abstract methods.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
6
A class must implement at least one interface.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
7
A class can implement more than one interface.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
8
If a class has an abstract method, then that class is automatically an interface.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
9
We can instantiate an object from an interface.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
10
Inheritance is useful for which of the following?

A) It declares the hierarchy of methods that are not common to all classes so they can be reused.
B) It allows superclasses to override subclasses.
C) It allows related classes to be organized into levels of functionality so they can be reused.
D) None of these is correct.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
11
Some OOP developers call a subclass the base class and call a superclass the derived class.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following are not inherited by subclasses?

A) public fields and public methods
B) private fields and private methods
C) protected fields and protected methods
D) All of these are correct.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
13
Why does Java provide a protected access modifier?

A) To hide methods from the client classes
B) To hide fields from client classes
C) So that fields and methods can be inherited by subclasses
D) All of these are correct.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
14
Why would you want to override a method?

A) It allows you to hide features of the subclass using the super keyword.
B) It allows you to hide features of the superclass that you want to change.
C) It allows you to make the inherited version of the method visible to the client of the subclass.
D) It allows you to invoke the base case method.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
15
The extends keyword specifies that the subclass inherits members of the superclass.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
16
If the call to the direct superclass constructor was not the first statement in the constructor, a compiler error will be generated.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
17
When a class extends another class, the default constructor of the subclass automatically calls the default constructor of the superclass. This is called explicit invocation.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
18
Why does using the protected access modifier compromise encapsulation?

A) Multiple classes can set the value of an instance variable defined in another class.
B) When a class does change a protected value, there is added maintenance complexity.
C) Subclass methods that directly set the value of a protected instance variable need to be verified.
D) When high performance is essential, superclass methods can be used to change the value of protected variables.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
19
Typically, an abstract class is a class that is not completely implemented.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
20
Several classes implement an interface, but all of them implement the same method using the same code. To provide a common method for all of these classes, you would create an abstract class.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
21
The following code will run without errors:
// Figure is an abstract class
Figure f = new Figure( );
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following is true of polymorphism?

A) It simplifies the processing of various elements in the same class hierarchy.
B) To use polymorphism, the classes must be in a different hierarchy.
C) In Greek, the term means "many changes."
D) All of these are correct.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
23
To use polymorphism, the classes must be in a different hierarchy.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following cannot be an interface member?

A) A class
B) A constant
C) A mutator method
D) An abstract method
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
25
An interface can contain one or more static constants.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
26
Which Java keyword do we use in the constructor of a class inheriting from another class if we want to call the constructor of the inherited class?

A) call
B) super
C) constructor
D) clone
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is correct regarding constructors?

A) Constructors are inherited but cannot be accessed.
B) Constructors are inherited and can be accessed.
C) Constructors are accessible but are not inherited.
D) Constructors are not inherited and cannot be accessed.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
28
An abstract method:

A) has a "do-nothing" body.
B) does not have a body.
C) has a body that operates like any other method.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
29
When is it determined which method is called when using polymorphism?

A) At compile time
B) At the time of writing code
C) At runtime
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is the correct definition of polymorphism?

A) One form only
B) Two forms only
C) Multiple forms
D) No form
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
31
A method in a subclass overriding a method in a superclass cannot call the superclass method.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
32
Overriding a method and overloading a method mean the same thing.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
33
Abstract methods can be static.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
34
Abstract methods can be private.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
35
Abstract methods can be overridden.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
36
A constructor can be declared abstract.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
37
An interface can contain instance variables.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
38
An interface can contain a constructor.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
39
_________ allows us to use the same method call for any object in a class hierarchy.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
40
Which keyword do we use in the header of a class that inherits from another class?

A) inherits
B) extends
C) protected
D) modifies
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
41
When class B inherits from class A:

A) A is the superclass and B is the subclass.
B) A is the subclass and B is the superclass.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
42
Assuming that class B inherits from class A and method foo belongs to class A, what do we mean by overriding method foo in class B?

A) We are calling method foo in class B.
B) We are not using method foo in class B.
C) We are replacing the superclass version of the foo method with a new foo method with the same signature.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
43
Assuming that class B inherits from class A, which of the following is correct?

A) An object of class B is an object of class A.
B) An object of class A is an object of class B.
C) An object of class B is an object of class A and an object of class A is an object of class B.
D) None of these is correct.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
44
What keyword do we use in the class header that inherits from an interface?

A) inherits
B) interfaces
C) implements
D) modifies
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
45
When a class implements an interface:

A) it does not have to implement the abstract methods of the interface.
B) it has to implement at least one of the abstract methods of the interface, but not all of them.
C) it has to implement all of the abstract methods of the interface.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
46
Private fields and methods are inherited.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
47
Private fields and methods are part of the inheriting class object.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
48
Public fields and methods are inherited.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
49
Protected fields and methods are inherited.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
50
When calling the constructor of a superclass from the constructor of the subclass, the call to that superclass constructor must be the first statement in the subclass constructor.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
51
Typically, an abstract class is a class that is not completely implemented.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
52
Usually, an abstract class contains at least one abstract method.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
53
We can instantiate an object from an abstract class.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
54
If a class has an abstract method, then that class must be declared abstract.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
55
Abstract methods can be called.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
56
Inheritance helps organize related classes into __________.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
57
An abstract class is declared to be abstract by including the __________ keyword in the class header.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
58
The interface concept is Java's way of implementing __________ inheritance.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
59
Because the private instance variables of a class are not inherited, how can the methods of a subclass access the values of these private instance variables?
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
60
Suppose you write a program in which you attempt to use a subclass to directly access a private password field in a superclass. Predict what will happen, and suggest a solution that would result in a different outcome.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
61
You have written a SavingsAccount class based on the BankAccount class in the textbook. You wish to instantiate a SavingsAccount object with a starting balance of $2,175.25. Theorize why you would need to provide an overloaded constructor for the SavingsAccount class.
Unlock Deck
Unlock for access to all 61 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 61 flashcards in this deck.