Test Questions & Answers Inheritance Ch.8 - Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis by John Lewis, Peter DePasquale, Joe Chase. DOCX document preview.

Test Questions & Answers Inheritance Ch.8

Chapter 8: Inheritance

Multiple Choice Questions:

1) The process of inheritance should establish a(n) ___________________ relationship.

a) is-a

b) has-a

c) static

d) not-a

e) none of the above

2) The original class that is used to derive a new class using inheritance is called ____________________ .

a) a superclass

b) a parent class

c) a base class

d) all of the above

e) neither a, b, nor c

3) __________ occurs when a child class defines a method with the same signature as a method in the parent class.

a) Overloading

b) Overriding

c) Overwhelming

d) Substituting

e) A child class cannot define a method with the same signature as a parent class method.

4) In order for derived classed to have access to encapsulated data members and methods of superclasses, the data members and methods should be declared using the ____________________ modifier.

a) private

b) public

c) protected

d) final

e) static

5) A child class can access private members of a parent class by

a) using super in front of the member name

b) using the member name directly

c) using this in front of the member name

d) using the public accessor and mutator methods defined in the parent class

e) A child class cannot access private members of a parent class.

6) When a variable declared in a subclass has the same name as a variable declared in a superclass, it is called a _______________ variable.

a) final

b) shadow

c) static

d) dead

e) this is not allowed in Java

7) A(n)______________________ class represents a generic concept in a class hierarchy.

a) super

b) abstract

c) interface

d) shadow

e) generic

8) A class declared as final _________________________________ .

a) cannot be changed.

b) cannot have subclasses.

c) cannot have superclasses.

d) has several abstract methods.

e) cannot be used in a program.

9) Which of the following key words indicates a method that cannot be overridden in a derived class?

a) super

b) final

c) extends

d) inherits

e) expands

10) To invoke a parent’s constructor in a subclass, we use the ______________ method.

a) abstract

b) construct

c) parent

d) super

e) extends

11) Which of the following statements is not a general inheritance practice that you should keep in mind in the design of a program?

a) Derived classes should have an “is-a” relationship with the parent classes.

b) Use the final key word when defining parent classes.

c) Avoid shadowing inherited variables when possible.

d) Define abstract classes to specify a common class interface for concrete derived classes.

e) All of these are general inheritance practices that should be considered when designing a program.

12) All Java classes are subclasses of the ___________________ class.

a) String

b) java.lang

c) Java

d) Class

e) Object

13) When designing a class hierarchy, it is important that common features be ________________________ .

a) higher in the class hierarchy.

b) lower in the class hierarchy.

c) near the middle of the class hierarchy.

d) in abstract classes.

e) in the Object class.

14) Which of the following methods are included in every class created in Java by inheritance?

a) next

b) toString

c) compareTo

d) charAt

e) none of the above

15) Of the classes below, the one that is most likely to be declared abstract is _________________.

a) Bat

b) Squirrel

c) Animal

d) Iguana

e) Parrot

1) A parent class object must be created before objects of a child class can be created.

2) Private members of a parent class are inherited by child classes.

3) Java supports multiple inheritance.

4) In Java, a subclass can only extend one parent class.

5) A child class is allowed to define a method with the same name and parameter list as a method in the parent class.

6) A child class is allowed to declare a variable with the same name as one that is contained in the parent class.

7) An abstract class must contain abstract methods.

8) It makes sense to declare most abstract classes as final.

9) It is possible to derive a class from an abstract class without overriding all of the parents abstract methods.

10) Inheritance should not be considered in the software design process.

1) Explain why inheritance is useful.

2) Compare and contrast the private visibility modifier to the protected visibility modifier. Why is the protected visibility modifier a better choice in an inheritance hierarchy?

3) Suppose we create a subclass from a class that has a method called someMethod. If we override someMethod in the subclass, is it possible to access the superclass's version of someMethod? If so, how?

4) Can a class be a parent of more than one subclass? Can a class be a child of more than one parent? Explain.

5) Explain the relevance of the Object class to the Java programming language.

6) What is an abstract class, and why might it be useful in an inheritance hierarchy?

7) Explain how a subclass can can access its parent classes private instance variables and methods.

8) A programmer tries to create a subclass of String called MyString. When the programmer compiles her new class, the compiler produces the following message:

MyString.java:1: cannot inherit from final java.lang.String

public class MyString extends String {

^

1 error

Explain the cause of this error.

9) Draw a hierarchy of Animals. The hierarchy should include the following entities: Animal, Reptile, Mammal, Bear, Human, Iguana, and Dolphin. Note that an Iguana is a Reptile, a Bear is a Mammal, a Human is a Mammal, and a Dolphin is a Mammal.

10) Consider a software system that will implement the following classes: Student, Professor, StaffMember, ContractWorker. List some common attributes of these classes. What would be a good abstract class from which these classes may be extended via inheritance?

11) Explain what it means for a child class to override a method in a parent class. Why might this be useful?

12) Why is it considered a good practice to override the toString and equals methods?

13) Describe the behavior of the toString method and the equals method of the Object class.

14) What does it mean for a class to be declared as final? What does it mean for a method to be declared as final?

15) What is a shadow variable?

Document Information

Document Type:
DOCX
Chapter Number:
8
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 8 Inheritance
Author:
John Lewis, Peter DePasquale, Joe Chase

Connected Book

Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis

By John Lewis, Peter DePasquale, Joe Chase

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party