Week 6 Part 2 Flashcards

1
Q

Hiding complexity and only displaying relevant features of an object. Implementation details hidden, user only sees functionality

A

Abstraction

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

How do we implement abstraction in Java?

A

Interfaces to define expected behaviour
and the abstract class - gives incomplete functionality

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

Can an abstract class be instantiated into an object?

A

No, it’s just a template. Needs to be extended to a concrete class.

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

T/F - Both classes and methods can be made abstract

A

True

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

T/F - Abstract methods have a body, classes are just templates

A

False. Abstract methods do not have a body.

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

T/F - if a method is abstract, the class must be abstract

A

True

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

An abstract method is used to specify a _________

A

behaviour

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

T/F - an abstract method is an instance method with they keyword abstract in its declaration

A

True, it’s just a line

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

An abstract class can force all of its derived classes to define their own implementation of a behaviour by defining it as an abstract method

A

?okay

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

T/F - You should not create objects of an abstract class

A

True

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

This class can be defined as an abstract class, even if it does not define any abstract method

A

Base class (where other classes are derived)

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

What happens if a derived class does not implement all the abstract metods of its base class?

A

It must also be defined as an abstract class

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

Class abstraction means to separate class ______________ from the ___ of the class

The creator of the class provides a description
of the class and let the user know how the class
can be used.

The user of the class does not need to know
how the class is implemented.

The detail of implementation is _______________
and hidden from the user

A

implementation from the use

encapsulated

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

3 advantages of abstract methods

A
  1. To make code more concise
  2. To enforce inheritance
  3. To ensure that the subclasses do not override the abstract method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Abstract methods help to ensure that any
object that ______s from an abstract class
must have implemented ________
methods that can be used by clients.

A

extends, concrete

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

Abstraction enforces a kind of contract
between an _______ and its ____

A

object, user

17
Q

If a single method is abstract, the class is?

A

Abstract

18
Q

Abstract method(s) are always contained in

A

abstract classes

19
Q

An abstract class may contain

A

no abstract methods

20
Q

Does a subclass need to implement ALL of the abstract methods of the superclass?

A

Yes, unless it’s also abstract

21
Q

Can you create an instance of an abstract class?

A

no