Inheritance Flashcards

1
Q

How many superclasses can be specified for a subclass?

A

One

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

Can a subclass access private members of its superclass?

A

No. inheritance doesn’t overrule private access restriction.

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

Accessor methods

A

Provide access to private members of a class

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

Which constructor creates an object given class inheritance?

A

The superclass constructor creates the superclass portion of the object & the subclass constructor creates the subclass portion.

The superclass portion of the object is constructed automatically using its default constructor.

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

How can a subclass call a constructor defined by its superclass?

A

super()

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

In a multilevel hierarchy, which constructor will superclass refer to?

A

The constructor in the closest superclass

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

How can you access superclass methods?

A

Super()

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

When are constructors executed in a class hierarchy?

A

Constructors execute in order of derivation from superclass to subclass

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

Can a reference variable of a superclass be assigned a reference to an object of a subclass?

A

Yes

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

Reference variable

A

Used to refer to an object

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

Can reference variables refer to objects of different class types?

A

No

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

What members do you have access to with a superclass reference variable?

A

The parts of the object defined by the superclass

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

How do you construct a copy of an object?

A

Define a constructor that takes an object of the class as its parameter

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

Method Overriding

A

When a method in a subclass has the same return type and signature as a method in its superclass.

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

When you call an overridden method in a subclass, which method is returned?

A

It will always refer to the subclass method

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

How do you access the superclass version of an overridden method?

A

Use super.method()

17
Q

Are methods overridden if their signatures differ?

A

No, they are simply overloaded.

18
Q

Dynamic method dispatch

A

The mechanism by which a call to an overridden method is resolved at run time rather than compile time.

Known as run time polymorphism

19
Q

Why is Polymorphism useful?

A

It allows a general class to specify methods common to all derivatives, while allowing subclasses to define the specific implementation of some or all of those methods.

20
Q

Abstract Class

A

Defines methods for its subclasses but does not provide an implementation

21
Q

Abstract Method syntax

A

abstract type name(parameter);

22
Q

What is in the body of an abstract method?

A

Nothing - it has no body

23
Q

Where can abstract modifiers not be used?

A

static methods or constructors

24
Q

When must a class be declared abstract?

A

When it contains one or mor abstract methods

25
Can an abstract class have objects?
No
26
When a subclass inherits an abstract class, what must it do to not be declared abstract as well?
Implement all abstract methods
27
Final
Modifier used to prevent: a method from being overridden a class from being inherited a variable from being changed Convention for finals is upper class names
28
Object class Methods
``` Clone() equals() finalize() getClass() notify() notifyAll() toString() wait() ```
29
What is the purpose of the toString() method?
It returns a string description of the object Many classes override this method to tailor a description of objects created