Unit 9 - Inheritance Flashcards

1
Q

Superclass

A

Class hierarchy can be developed by putting common attributes & behaviors of related classes into a single class

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

Subclasses

A
Extend a superclass
Can draw upon existing attributes & behaviors of superclass without repeating in code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Extending a subclass from a superclass creates an

A
"is-a" relationship from subclass to superclass
(Lower class) is a (Upper class)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Inheritance

A

Parent classes have attributes & behaviors that can be inherited by child classes

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

Why use inheritance

A

Code reusability
Prevents repeating code
Readability & organization
Ease of maintenance

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

Each subclass can only have

A

one superclass

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

All subclasses inherit

A

attributes and methods of their superclasses

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

A superclass can’t

A

inherit attributes and methods of subclass implicitly

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

keyword extend

A
Used to establish an inheritance relationship between subclass and a superclass
Can only extend one superclass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Constructors are

A

NOT inherited

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

When a subclass’s constructor does not explicitly call a superclass’s constructor using super,

A

Java inserts a call to superclass’s no-argument constructor

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

Superclass constructor can be called from first line of subclass constructor by using

A

keyword super and passing appropriate parameters

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

Actual parameters passed in call to superclass constructor provides

A

values that constructor can use to intialize the object’s instance variabes

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

Using super will call

A
No-argument constructor of superclass
MUST be the first line of body of constructor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Whether superclass constructor is called implicitly or explicitly, process of calling superclass constructors continue up

A

inheritance hierarchy with each constructor calling constructor of superclass until Object constructor is called

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

Method overriding occurs when

A

a public method in a subclass has the same method signature as a public method the superclass

17
Q

Any method that is called must be defined withint tis

A

own class or superclass

18
Q

Subclass is usually designed to have

A

modified or additional methods or instance variables

19
Q

Subclass inherit all

A

public methods of superclass and will remain public in subclass

20
Q

What are options with methods when we extend a superclass?

A

Inherit methods
Write new methods
Override methods

21
Q

Inherit methods

A
Public methods in superclass become valid public methods of subclass
Important to acces private instance variables
22
Q

Write new methods

A
Additional methods completely independent of methods in superclass
Includes overloaded methods and treated as independent methods
23
Q

Override methods

A

Write a new or different implementation of a method that already exists in superclass

24
Q

keyword super

A

Can be used to call superclass’s constructors and methods

25
Superclass method can be called in a subclass by using
keyword super with method name and passing appropriate parameters
26
Subclass
Class that extends another class
27
Superclass
Class being extended
28
Polymorphic reference variable
``` Can refer to objects from different classes at different points in code Can store a reference to its declared class or tan any subclass of its declared class ```
29
Why would we declare a variable using a superclass if we plan to store a reference to a subclass object?
A collection needs to be declared as a data type
30
If s is a subclass of T, then assigning an object of type s to a reference of type t facilitates
polymorphism T obj = new S(arguments)
31
If s is a subclass of T, then a reference of type T can be used to refer to
An object of type T or S
32
Declaring references of type T when s is a subclass of T is useful in followin declarations
Formal method parameters | Arrays T[ ] var or ArrayList ,T> var
33
Method is considered polymorphic when it is
overridden in at least one subclass
34
Polymorphism
Act of executing an overridden non-static method from correct class at runtime based on actual object type
35
Object superclass
Superclass of all other classes in Java
36
When a class does not expliciting extend another class, then
it implicitly extends Object
37
Subclasses of Object often
override the equals and toString methods with class specific implementations
38
When an object is passed as a parameter to the print() or println() method,
object's toString() method is implicitly called