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?

A
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
Q

What are the differences between base classes and derived classes?

A

Base classes are “more general” (mammal) and derived classes are “more specific” (cat)

26
Q

What would a UML diagram of the relationships of the base/derived classes look like?

A
27
Q

What are some characteristics and uses of base/derived classes?

A
28
Q

What are protected members?

A
29
Q

What to use private or protected fields?

A
30
Q

How to use lambda functions to create methods in a class?

A

Look at the arrow function syntax.

31
Q

Can you change the access modifier when overriding a method?

A
32
Q

Best way to create variable that only need to be get?

A

First initialize the values in the constructor then do a property with get only auto generated;

33
Q

Best way to create and use an instance variable that needs get and protected set?

A

first create private instance variable, then a property that gets and protected sets.

34
Q

What does DRY mean?

A

Dont Repeat Yourself

35
Q

What would constructor (passing) look like?

**cant remember the name **

A
36
Q

What do the virtual and abstract keywords do?

A
37
Q

Where can using protected instance variables cause problems?

A
38
Q

What is the base. method invocation and when should it be used?

A
39
Q

How do constructors in derived classes work?

A
40
Q

What are the main benefits to inheritance?

A
41
Q

What does the ToString method do?

A
42
Q

What does the Reference-Equals method do?

A
43
Q

What does the Memberwide-Clone method do?

A
44
Q

What does the GetType method do?

A
45
Q

What does the GetHashCode method do?

A
46
Q

What does the Finalize method do?

A
47
Q

What does the Equals method do?

A
48
Q
A