2. Inheritance Flashcards

1
Q

What is inheritance?

A

Inheritance is the act of creating new classes based on existing classes.

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

What does inheritance allow us to do?

A

It allows us to take all the same members that are used by a given set of classes and extract them into they’re own class.

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

What is an abstract class?

A

An abstract class is a class that contains all the business logic that a normal class would use, but it cannot be directly instantiated.

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

What is the purpose of an abstract class?

A

To have its functionality extended by classes that inherit it.

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

How is an abstract class defined?

A

By using the abstract modifier on a class.

eg. abstract class Computer { … }

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

How does a class extend another?

A

By specifying its name after a column next to its own name.

eg. class Desktop : Computer { … }

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

What is the default access modifier for classes?

A

The default access modifier for classes is internal.

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

What is the base keyword?

A

base is a keyword that’s used by child classes to refer to their parent class.

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

How does a child class override the property of its base class?

A

By defining a property that its base class already has, using the override keyword.

eg. public override string Name { get; set; }

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

How does a child class define a new property with the same name as its base class?

A

By defining the same property and using the new keyword.

eg. public new string Name { get; set; }

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

Can a child property/method override a “normal” property/method of its base class?

A

No. In order for a base class property or method to be overridden, it needs to be marked as virtual or abstract.

eg. public virtual string Name { … }

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

How does a child class access the properties of its base class?

A

By using the base keyword.

eg. base.Name

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

What is the virtual keyword?

A

It’s a modifier that indicates that the given property/method CAN be overridden by a child class.

eg. public virtual string Name;

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

What is the abstract keyword?

A

It’s a modifier that indicates that the given property/method MUST be overridden by a child class.

eg. public abstract string Name;

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

How do you define a setter or a getter so that it can only be called from within the class?

A

By using the private access modifier.

eg. { private get; /* and/or */ private set; }

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

What is a guard clause?

A

It’s a block of code that checks for a condition and returns out of the code depending on the outcome.