C# Classes / Objects / Inheritance Flashcards

1
Q

What does overloading constructors mean?

A

Overloaded constructors enable objects of a class to be conveniently initialized in different ways. To overload constructors, simply provide multiple constructor declarations with different signatures.

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

What is the special use case for the this keyword to prevent code duplication for constructor overloading?

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

What is a common gotcha when dealing with constructors?

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

What is a constructor initializer?

A

: this(time.Hour, time.Minute, time.Second) { }

This is called a constructor initializer. Enables a class to reuse initialization code provided by a constructor, rather than defining similar code in another constructor.

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

What is the nameof operator?

A

It’s common to include in an exception’s error message a variable’s or property’s identifier. As of C# 6, you can instead use the nameof operator, which returns a stringrepresentation of the identifier enclosed in parentheses.

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

What is garbage collection and what are destructors?

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

What are readonly Instance variables?

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

When should you use readonly over const?

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

When to use const over readonly?

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

How do you auto implement getter property and readonly?

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

What is the object browser?

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

What is the object initializer syntax look like when there is no perfect constructor for your needs but the instance variables are there?

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

What is operator overloading?

A

You can create operators that work with objects of your own types — via a process called operator overloading. You can overload most operators!

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

What is a Struct and when should you use one over a class?

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

What would overloading an operator in a stuct look like?

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

What would overloading the - and * operators look like?

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

What can’t you do with a struct?

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

What keyword is used to overload operators?

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

Can you overload an operator method for two different types?

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

What are extension methods?

21
Q

What is inheritance?

A

Inheritance allows a new class to absorb an existing class’s member. A derived class normally adds its own fields and methods to represent a more specialized group of objects. Inheritance saves time by reusing proven and debugged high-quality software.

22
Q

What is a direct base class?

A

The direct base class is the base class which the derived class explicitly inherits

23
Q

What is an indirect base class?

A

An indirect basae class is any class above the direct base class in the class hierarchy. The class hierarchy begins with class object.

24
Q

Which type of relationship represents inheritance?

A

The is-a relationship

eg. a car “is a” vehicle

a dog “is a” specialized kind of mammal

25
What are the differences between base classes and derived classes?
Base classes are "more general" (mammal) and derived classes are "more specific" (cat)
26
What would a UML diagram of the relationships of the base/derived classes look like?
27
What are some characteristics and uses of base/derived classes?
28
What are protected members?
29
What to use private or protected fields?
30
How to use lambda functions to create methods in a class?
Look at the arrow function syntax.
31
Can you change the access modifier when overriding a method?
32
Best way to create variable that only need to be get?
First initialize the values in the constructor then do a property with get only auto generated;
33
Best way to create and use an instance variable that needs get and protected set?
first create private instance variable, then a property that gets and protected sets.
34
What does DRY mean?
Dont Repeat Yourself
35
What would constructor (passing) look like? \*\*cant remember the name \*\*
36
What do the virtual and abstract keywords do?
37
Where can using protected instance variables cause problems?
38
What is the base. method invocation and when should it be used?
39
How do constructors in derived classes work?
40
What are the main benefits to inheritance?
41
What does the ToString method do?
42
What does the Reference-Equals method do?
43
What does the Memberwide-Clone method do?
44
What does the GetType method do?
45
What does the GetHashCode method do?
46
What does the Finalize method do?
47
What does the Equals method do?
48