Unit 9 - Inheritance Flashcards

You may prefer our related Brainscape-certified 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
Q

Superclass method can be called in a subclass by using

A

keyword super with method name and passing appropriate parameters

26
Q

Subclass

A

Class that extends another class

27
Q

Superclass

A

Class being extended

28
Q

Polymorphic reference variable

A
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
Q

Why would we declare a variable using a superclass if we plan to store a reference to a subclass object?

A

A collection needs to be declared as a data type

30
Q

If s is a subclass of T, then assigning an object of type s to a reference of type t facilitates

A

polymorphism

T obj = new S(arguments)

31
Q

If s is a subclass of T, then a reference of type T can be used to refer to

A

An object of type T or S

32
Q

Declaring references of type T when s is a subclass of T is useful in followin declarations

A

Formal method parameters

Arrays T[ ] var or ArrayList ,T> var

33
Q

Method is considered polymorphic when it is

A

overridden in at least one subclass

34
Q

Polymorphism

A

Act of executing an overridden non-static method from correct class at runtime based on actual object type

35
Q

Object superclass

A

Superclass of all other classes in Java

36
Q

When a class does not expliciting extend another class, then

A

it implicitly extends Object

37
Q

Subclasses of Object often

A

override the equals and toString methods with class specific implementations

38
Q

When an object is passed as a parameter to the print() or println() method,

A

object’s toString() method is implicitly called