Inheritance Flashcards

1
Q

What is inheritance?

A

A mechanism where a new class (subclass) inherits properties and behaviors (methods) from an existing class (superclass).

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

How do you create a sub class?

A

Use the ‘extends’ keyword.
(class Dog extends Animal { )

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

What does the super() constructor call?

A

The super() call invokes the constructor of the super class. It must be the first statement in the subclass constructor.

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

What is polymorphism?

A

Polymorphism allows objects of different classes to be treated as objects of a common super class. The most common use is method overriding, where a subclass can define its own version of a method.

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

What is the difference between ‘is-a’ and ‘has-a’ relationships in inheritance?

A

is-a represents inheritance. (Dog is-a Animal)

has-a represents composition. (Car has-a Engine)

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