Objects - Inheritance Flashcards

1
Q

What are the four core principles of OOP?

A

Encapsulation, inheritance, polymorphism and abstraction.

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

Subclasses

A

Subclasses inherit the attributes and behaviors of the more general classes.

When you write a class, you usually want to try and make it as general and open ended as possible so that you can reuse it in other programs that you write.

A subclass is taking a more general class and then adding the needed functionality to it that is specific to the current program that you are working on.

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

How do you spewcify a class as a subclass?

A

You add a colon after the name of the SUBclass that you are making, followed by the name of the CLASS that you are extending.

class NewSubClass : OriginalClass
{

}

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

When creating a subclass, what do you need to make sure and do when adding it’s parameters?

A

You need to include the base class’s parameter’s as well so that they can be satisfied.

You do this by adding a colon after the SUBCLASS’s parameters have been laid out, then adding the keyword “base” followed by the parameters that the base class takes.

public NewSubClass (int x, int y) : base(x, y)
{

}

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

What are other terms for base class?

A

Parent Class or Super Class

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

What are other names for Sub Class?

A

Child Class or Derived Class

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

What does the “is” operator do?

A

It will return true if a variable is of a given type.
You use this to preform a type check.

Console.WriteLine(x is MapLocation);

will tell you T or F as to weather or not x is of the type MapLocation.

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

What are exceptions used for?

A

They are used to communicate that an error has happened.

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

How do you create an object of an exception that you’ve made?

A

In the catch declairation, you add a variable name in the parameters next to the exception’s name.

catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

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