Week 9 Flashcards

1
Q

A feature that allows us to perform an action in different ways

A

Polymorphism

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

Does polymorphism allow you to program in the general or the specific?

A

Polymorphism allows you to program in the general, rather than the specific

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

T/F - Polymorphism enables you to write programs that process objects that share the same superclass as if they were all objects of the superclass

A

True

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

A type defined by a subclass is called a _______, and a type defined by a superclass is called a _________

A

subtype, supertype

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

The key concept of polymorphism: “Relying on each object ‘knowing how…’ to do what?

A

Knowing how to do the right thing in response to the same method call

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

Why polymorphism powerful?

A

Makes the class flexible and extensible, simplifies programming by providing a single interface

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

Method overriding allows subclasses to do what?

A

Allow for the reuse of code
Subclasses can use all the general definitions the superclass provides and add specializations by overriding methods

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

What is the difference between polymorphism and inheritance?

A

Inheritance applies the behaviour of a superclass to a subclass.

Polymoprhism changes the behaviour of the superclass in the subclass.

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

These are useful for assigning common functionality to possibly unrelated classes:

A

Interfaces

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

2 unrelated classes implement the same interface, what happens with their methods and objects?

A

Classes that implement the same interface can have their objects respond to all of the interface method calls

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

T/F - There are more types of polymorphism than inheritance

A

False, there are 2 types of polymorphism, 5 types of inheritance

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

With polymorphism, we can design and implement systems that are _______ _________

A

easily extensible

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

T/F - Interaces are useful for assigning common functionality to possibly unrelated classes

A

True

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

T/F - Polymorphism enables you to deal in specifics

A

False, Polymorphism enables you to deal in generalities

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

T/F - Objects will behave in an appropriate manner even if you do not know their type, as long as they belong to the same inheritance hierarchy

A

True

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

How does polymorphism promote extensibility?

A

Software that invokes polymorphic behavior is independent of the object type that it is being used by

You can add new objects types without changing the base system

Only the client code that instantiates new objects must be changed

17
Q

What is a polymorphic reference?

A

A variable that can refer to different types of objects at different points of time

18
Q

T/F - All object references in Java are potentially polymorphic

A

True

19
Q

T/F - A method invoked through a polymorphic reference cannot change form from one invocation to the next

A

False

20
Q

Static polymorphism has method ________ing, dynamic polymorphism has method _________ing

A

Method overloading, method overriding

21
Q

How does method overloading different from method overriding?

A

Overloading is done at compile time, overriding at run-time

22
Q

Overidden vs. Overriding. How do they differ?

A

Overridden = parent class method
Overriding = child class method

23
Q

Can the argument list differ when method overriding?

A

No, must be same type and sequence

24
Q

I have a superclass method that is public, in the subclass I make the method private, will this work?

A

No. The access modifier cannot be more restrictive than the overridden method of the parent class

25
Q

Can private, static, or final methods be overriden? What is the caveat?

A

No, no, and no. Static methods can be re-declared, which would make the method act differently be completely separated from the superclass method

26
Q

Java defers method binding until run time, what is this called?

A

Dynamic binding, or late binding

27
Q

What would happen if binding was done at compile time?

A

It would call the same method every time

28
Q

Definition: Linking between the method call and method implementation is resolved at compile time

A

Static binding