Programming Languages Chapter 09 After The Constructor For Class Executes The

subject Type Homework Help
subject Pages 5
subject Words 1217
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 9 Object Oriented Programming: Inheritance
Section 9.1 Introduction
9.1 Q1: Which of the following statements is false?
a. A subclass is often larger than its superclass.
b. A superclass object is a subclass object.
c. The class following the extends keyword in a class declaration is the direct superclass of the class
being declared.
d. Java uses interfaces to provide the benefits of multiple inheritance.
9.1 Q2: Inheritance is also known as the
a. knows-a relationship.
b. has-a relationship.
c. uses-a relationship.
d. is-a relationship.
9.2 Q1: 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.
9.2 Q2: An advantage of inheritance is that:
a. All methods can be inherited.
b. All instance variables can be uniformly accessed by subclasses and superclasses.
c. Objects of a subclass can be treated like objects of their superclass.
d. None of the above.
9.3 Q1: 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.
9.3 Q2: Using the protected keyword also gives a member:
a. public access.
b. package access.
c. private access.
d. block scope.
page-pf2
9.3 Q3: Superclass methods with this level of access cannot be called from subclasses.
a. private.
b. public.
c. protected.
d. package.
9.4 Q1: Which of the following statements is false?
a. A class can directly inherit from class Object.
b. It's often much more efficient to create a class by inheriting from a similar class than to create the class
by writing every line of code the new class requires.
c. If the class you're inheriting from declares instance variables as private, the inherited class can access
those instance variables directly.
d. A class's instance variables are normally declared private to enforce good software engineering.
9.4.1 Q1: Every class in Java, except ________, extends an existing class.
a. Integer.
b. Object.
c. String.
d. Class.
9.4.1 Q2: Overriding a method differs from overloading a method because:
a. Overloaded methods have the same signature.
b. Overridden methods have the same signature.
c. Both of the above.
d. Neither of the above.
9.4.2 Q1: To avoid duplicating code, use ________, rather than ________.
a. inheritance, the “copy-and-past” approach.
b. the “copy-and-paste” approach, inheritance.
c. a class that explicitly extends Object, a class that does not extend Object.
d. a class that does not extend Object, a class that explicitly extends Object.
page-pf3
9.4.3 Q1: Consider the classes below, declared in the same file:
class A
{
int a;
public A()
{
a = 7;
}
}
class B extends A
{
int b;
public B()
{
b = 8;
}
}
Which of the statements below is false?
a. Both variables a and b are instance variables.
b. After the constructor for class B executes, the variable a will have the value 7.
c. After the constructor for class B executes, the variable b will have the value 8.
d. A reference of type A can be treated as a reference of type B.
9.4.3 Q2: Which of the following is the superclass constructor call syntax?
a. keyword super, followed by a dot (.) .
b. keyword super, followed by a set of parentheses containing the superclass constructor arguments.
c. keyword super, followed by a dot and the superclass constructor name.
d. None of the above.
9.4.4 Q1: 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.
9.4.4 Q2: Which statement is true when a superclass has protected instance variables?
a. A subclass object can assign an invalid value to the superclass’s instance variables, thus leaving an
object in an inconsistent state.
b. Subclass methods are more likely to be written so that they depend on the superclass’s data
implementation.
page-pf4
c. We may need to modify all the subclasses of the superclass if the superclass implementation changes.
d. All of the above.
9.4.5 Q1: 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.
9.4.5 Q2: 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.
9.5 Q1: When a subclass constructor calls its superclass constructor, what happens if the superclass’s
constructor does not assign a value to an instance variable?
a. A syntax error occurs.
b. A compile-time error occurs.
c. A run-time error occurs.
d. The program compiles and runs because the instance variables are initialized to their default values.
9.6 Q1: The default implementation of method clone of Object performs a ________.
a. empty copy.
b. deep copy.
c. full copy.
d. shallow copy.
9.6 Q2: The default equals implementation of class Object determines:
a. whether two references refer to the same object in memory.
b. whether two references have the same type.
c. whether two objects have the same instance variables.
d. whether two objects have the same instance variable values.
page-pf5
9.7 Q1: Class ________ represents an image that can be displayed on a JLabel.
a. Image.
b. Icon.
c. ImageIcon.
d. IconImage.
9.7 Q2: Which method changes the text the label displays?
a. changeText.
b. setText.
c. changeLabel.
d. setLabel.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.