Inheritance Flashcards

1
Q

What is inheritance?

A

A mechanism for deriving a new class from an existing one.

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

What is the motivation behind inheritance?

A

To reuse existing classes, rather than writing new ones.

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

What is the subclass or child or derived class?

A

The derived new class from a superclass. Who inherits the attributes and methods of the superclass.

It extends the superclass.

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

What’s the difference between public, private and protected visibilities?

A

Public: children classes can access them directly (except the constructor)

Private: children classes cannot access them directly.

Protected: only accessible by any class in the same package or by any subclass.

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

What’s the purpose of ‘super’?

A

It’s a reserved word used in a derived class to refer to its parent class.

Allows you to access those members of the parent class that are not inherited.

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

What should the first line of a child’s constructor be?

A

super(…);

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

Can a method defined with the ‘final’ modifier be overridden?

A

No.

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

Does the type of an object change?

A

No, it is solely determined when it is created.

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

What is Polymorphism?

A

The principle that behaviour of a method can vary, depending on the type of the object being referenced.

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

What is casting?

A

The process of making a variable behave as a variable of a another type.

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

When is casting allowed?

A

If a class shares an IS-A or inheritance relationship with another class or interface.

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