Inheritance|Polymorphism Flashcards

1
Q

What does a child class do?

A

inherits the accessible state and behavior of its
parent class.
○ private members are not accessible to the child class.
○ Child classes can access protected members in the parent.
○ Constructors are not inherited. The child class must define its own.
● Inheritance establishes an “is a” relationship between two classes.
○ The child is an instance of the parent.

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

What does inheritance allow?

A

Allows you to derive a specialized class from a more generalized class (parent, superclass, base class)
Derived class is the child class or subclass.
Child class inherits all states and behaviors, but adds specialized ones, can also modifying existing.

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

What is subclassing?

A

Refers to creating a child class that inherits parent class.

Using extends keywords:

public class Mammal extends Chordate {
}

Constructors are not inherited.

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

When do you use the super keyword?

A

If the parent class defines at least one constructor with parameters, the child class must invoke one of the constructors.

public class Child extends Parent {
private String name;
public Child(int x, String name) {
super(x);
this.name = name;
}}

super must be first line of constructor

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

What does Polymorphism mean?

A

A parent class can morph and access the state and behavior of it’s child.

A child class can be used anywhere it’s parent class is accepted.

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