Week 3 - inheritance Flashcards

1
Q

Describe inheritance in a UML diagram

A

Parent class (base or super class) such as Person with a child class (subclass) such as Employee. Employee is-a person and arrow points towards parent class

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

What reserved word establishes an inheritance relationship in Java?

A
Extends
ie the child class extends the parent class:
class Employee extends Person
{
// class contents
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

UMLs consist of

A

Class name
Attributes
Methods

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

Multiplicity (cardinality) are

A

Notations placed near the end of an association. Ie a company class may have ‘1’ to denote there is only 1 company but an employee class may have ‘1..*’ To denote “1 or more”

1 - no more than one

  1. .1 - zero or one
    * - many
  2. .* - zero or many
  3. .* - one or many
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Inheritance allows you to derive a new __________ from an existing one.

A

Class

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

What reference is used to invoke the parents constructor?

A

Super

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

Describe protected access

A

Protected data can be accessed by methods of the object class and all its subclasses.

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

True or fale: private data is inherited?

A

False. Private data isn’t inherited. Public data is

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

A super reference is used to invoke a parents constructor. How is a parent method invoked?

A

super.()

This is known as over riding the parents method (the inherited method can then be changed)

Methods declared as ‘final’ modifier cannot be overridden.

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

Inheritance allows what…

A

Inheritance allows you to derive a class fork an existing one (is Employee is-a Person)

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

Polymorphism is…

A

… the ability of one object type to be treated as though it was another type

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

Polymorphism allows methods of the same name to behave in different ways? True or false?

A

True.

By having the same name but different parameters it allows the method to literally have ‘many forms’

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

toString() is a _______ class

A

Object class.

Every time we define a toString method we are overriding the object class method

The toString method in the object class is defined to return a string

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

Can you create objects in an abstract class?

A

No.

A concrete class is one in which you can create objects.

A base(parent/ super) class can be declared as Abstract to force implemented to create concrete classes from subclasses(child classes) only.

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