Inheritance Flashcards

1
Q

The process of creating derived classes from a base class to enhance code reusability.

A

Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Inheritance relationship can be described as

A

superclass-subclass
is-a/an, is-a-kind-of
has-a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

the “is-a” rule states that __________ of the subclass is an object of the superclass

A

every object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You can use a subclass object whenever the program expects a superclass.

A

Substitution Principle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What features can be inherited by the subclass?

A

Public and Protected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The super constructor must always be the ____________ in another constructor.

A

first statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The collection of classes extending from a common superclass is called an ________________________

A

Inheritance Hierarchy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The path from a particular class to its ancestor is its ______________________.

A

Inheritance chain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When some methods in superclass is not appropriate for the subclasses, the solution is to _________________________

A

override methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When designing Classes, place the _______________ in the superclass

A

general methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Place the more ______________ in the subclass(es)

A

specialized methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Subclasses are more superior because they have more functionality than superclasses

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Benefits of Inheritance

A
  • Forms ranking or ordering of abstractions
  • Simplifies our understanding of a problem
  • Allows code reuse
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Java employs _______ inheritance

A

Single

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

top of hierarchy

A

java.lang.Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

All classes in the Java Platform are descendants of the _____________

A

Object class

17
Q

user within the subclass to refer to its superclass, or to invoke constructor, method or attribute (discouraged) of the super class.

A

Super keyword

18
Q

constructors are not inherited.

19
Q

Redeclaring and redefining a method of the superclass in the subclass

A

Method Overriding

20
Q

In overriding a method, the _____ and _________ (name, parameter types) should be the same as the original method

A

return type, method signature

21
Q

When overriding a method, the access modifier should be the same or less strict.

22
Q

Given the method:

int add (int x, int y);

is the method overriding:

protected int add (int a, int b);

valid?

A

YES, from default to a less strict access modifier (protected)

23
Q

With ___________ keyword, there is no need to implement the method (no method body required)

24
Q

For added clarity, a class with one or more abstract methods must itself be declared abstract

25
Other than the abstract methods, an abstract class can have attributes and concrete methods, just like any normal class
TRUE
26
are classes designed to become superclasses
Abstract Classes
27
TRUE or FALSE: You can instantiate abstract classes.
FASLE
28
TRUE or FALSE: When a method is abstract in the superclass, the subclass has the option not to override it.
FALSE. All abstract methods from the superclass must be overridden by the derived class.
29
are classes designed to be leaf nodes in the hierarchy. That is, final classes cannot be extended.
Final Classes
30
________________ cannot be overridden by the subclasses
Final methods
31
Problems of Inheritance
Yoyo Problem * When understanding the behavior of an object whose class comes from a hierarchy, we might have to go up and down the hierarchy to trace the behavior. Dependency Problem * Stability and existence of a subclass demands the same from a superclass. * Therefore when “transporting” a superclass B, it must be transported with its superclasses. Size and Efficiency Problem * Note that subclasses are actually larger than their superclasses (although they might appear to be written with less code). * Sometimes, not all inherited methods are required in a given problem. * It does save us programming time but performance may suffer when dealing with larger than required objects. * Therefore, inheritance trees should be as shallow as possible.