Exam 8: Inheritance

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Consider an 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?

Free
(Essay)
4.9/5
(34)
Correct Answer:
Verified

Some common attributes would be socialSecurityNumber, age, and address. A good abstract class from which these classes could be extended is Person.

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

Free
(Multiple Choice)
4.7/5
(41)
Correct Answer:
Verified

A

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

Free
(Short Answer)
4.7/5
(32)
Correct Answer:
Verified

A method declared as final cannot be overridden by any subclass. A class declared as final can not be extended via inheritance.

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?

(Essay)
4.9/5
(43)

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

(Multiple Choice)
5.0/5
(31)

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

(Short Answer)
4.7/5
(36)

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

(Essay)
4.9/5
(44)

The derived class created using inheritace is called ______________________ .

(Multiple Choice)
4.9/5
(28)

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.

(Multiple Choice)
4.7/5
(33)

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

(True/False)
4.9/5
(40)

It makes sense to declare most abstract methods as final.

(True/False)
4.8/5
(45)

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

(Essay)
4.9/5
(32)

Methods and variables declared as private in a parent class cannot be accessed in a child class.

(True/False)
4.8/5
(50)

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

(Multiple Choice)
4.8/5
(38)

Java supports multiple inheritance.

(True/False)
4.8/5
(42)

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

(Essay)
4.9/5
(30)

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

(Essay)
4.8/5
(48)

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.

(Short Answer)
4.9/5
(37)

Once a method is overridden in a subclass, the original version can never be referenced from within the subclass.

(True/False)
4.7/5
(43)

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

(Essay)
4.9/5
(35)
Showing 1 - 20 of 40
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)