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

ملء الشاشة (f)
exit full mode
سؤال
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.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
An interface can contain one or more abstract methods.
سؤال
A class must implement at least one interface.
سؤال
A class can implement more than one interface.
سؤال
If a class has an abstract method, then that class is automatically an interface.
سؤال
We can instantiate an object from an interface.
سؤال
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.
سؤال
Some OOP developers call a subclass the base class and call a superclass the derived class.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
The extends keyword specifies that the subclass inherits members of the superclass.
سؤال
If the call to the direct superclass constructor was not the first statement in the constructor, a compiler error will be generated.
سؤال
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.
سؤال
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.
سؤال
Typically, an abstract class is a class that is not completely implemented.
سؤال
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.
سؤال
The following code will run without errors:
// Figure is an abstract class
Figure f = new Figure( );
سؤال
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.
سؤال
To use polymorphism, the classes must be in a different hierarchy.
سؤال
Which of the following cannot be an interface member?

A) A class
B) A constant
C) A mutator method
D) An abstract method
سؤال
An interface can contain one or more static constants.
سؤال
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
سؤال
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.
سؤال
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.
سؤال
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
سؤال
Which of the following is the correct definition of polymorphism?

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

A) inherits
B) extends
C) protected
D) modifies
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
What keyword do we use in the class header that inherits from an interface?

A) inherits
B) interfaces
C) implements
D) modifies
سؤال
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.
سؤال
Private fields and methods are inherited.
سؤال
Private fields and methods are part of the inheriting class object.
سؤال
Public fields and methods are inherited.
سؤال
Protected fields and methods are inherited.
سؤال
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.
سؤال
Typically, an abstract class is a class that is not completely implemented.
سؤال
Usually, an abstract class contains at least one abstract method.
سؤال
We can instantiate an object from an abstract class.
سؤال
If a class has an abstract method, then that class must be declared abstract.
سؤال
Abstract methods can be called.
سؤال
Inheritance helps organize related classes into __________.
سؤال
An abstract class is declared to be abstract by including the __________ keyword in the class header.
سؤال
The interface concept is Java's way of implementing __________ inheritance.
سؤال
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?
سؤال
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.
سؤال
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 Deck
1/61
auto play flashcards
العب
simple tutorial
ملء الشاشة (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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
5
An interface can contain one or more abstract methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
6
A class must implement at least one interface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
7
A class can implement more than one interface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
8
If a class has an abstract method, then that class is automatically an interface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
9
We can instantiate an object from an interface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
11
Some OOP developers call a subclass the base class and call a superclass the derived class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
15
The extends keyword specifies that the subclass inherits members of the superclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
19
Typically, an abstract class is a class that is not completely implemented.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
21
The following code will run without errors:
// Figure is an abstract class
Figure f = new Figure( );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
23
To use polymorphism, the classes must be in a different hierarchy.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
25
An interface can contain one or more static constants.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
31
A method in a subclass overriding a method in a superclass cannot call the superclass method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
32
Overriding a method and overloading a method mean the same thing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
33
Abstract methods can be static.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
34
Abstract methods can be private.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
35
Abstract methods can be overridden.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
36
A constructor can be declared abstract.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
37
An interface can contain instance variables.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
38
An interface can contain a constructor.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
39
_________ allows us to use the same method call for any object in a class hierarchy.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
46
Private fields and methods are inherited.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
47
Private fields and methods are part of the inheriting class object.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
48
Public fields and methods are inherited.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
49
Protected fields and methods are inherited.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
51
Typically, an abstract class is a class that is not completely implemented.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
52
Usually, an abstract class contains at least one abstract method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
53
We can instantiate an object from an abstract class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
54
If a class has an abstract method, then that class must be declared abstract.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
55
Abstract methods can be called.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
56
Inheritance helps organize related classes into __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
57
An abstract class is declared to be abstract by including the __________ keyword in the class header.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
58
The interface concept is Java's way of implementing __________ inheritance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 61 في هذه المجموعة.