C# Polymorphism / Interfaces / exception handling Flashcards

1
Q

What is polymorphism?

A

Plumorphist enables you to write apps that process objects that share the same base class in a class hierarchy as if they were all about objects of the base class. Polymorphism promotes extensibility.

eg. a dog, cat, and cow all inherit a speak class, but speaking can take “many forms” because the dog speak command woofs, the cat speak command meows and the cow speak command moos. Therefore one method can take many forms.

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

How would you demonstrate polymorphic behaviour?

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

How would you invoke methods on derived-class object using base-class variable?

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

If a base class variable contains a reference to a derived class object and is used to casll a virtual method, which medthod gets called?

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

What is an abstract class?

A

It is a base class the house common variables and methods to be used with derived classes to reduce/prevent code duplication.

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

What is a concrete class?

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

What are some differences in abstract/concrete classes?

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

Can constructors or static methods be declared abstract or virtual?

A

No

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

What happens if you fail to implement all of a base classes abstract methods?

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

What are some main uses for abstract classes and methods?

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

What would the UML diagram of an abstract class hierarchy look like?

A

Abstract classes at the top and in italic.

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

What would the different earnings and to string methods look like in an abstract hierarchy?

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

can you cast the reference stored in a base class variable back to a reference of the derived-class type?

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

How does the IS operator work?

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

What are the allowed assignment between base and derived class variables?

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

What are sealed methods?

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

What are sealed classes?

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

What is an interface?

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

What is the difference between an interface and an abstract class?

A

An interface explains adjectives (searchable, edible) and can group unrelate objects. Abstract classes still use the “is a” relationship and are nouns (shape, mammal)

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

How do you create and use an interface?

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

When would you use an interface over an abstract class?

A
22
Q

What is the naming convention for interfaces?

A

IName

eg. IPayable, IDrinkable

23
Q

What is good practive for method naming in an interface?

A
24
Q

How would a UML diagram look implementing an interface?

A
25
Q

What does the syntax look like for creating an interface?

A
26
Q

Hopw would you implement an interface to a class?

A
27
Q

Can a derived class inherit from more than one base class?

A
28
Q

Can a class implement more than one interface? if so how?

A

Yes.

public abstract class Employee : IPayable, IListable

29
Q

How would you use an interface to use a method and class polymorphically?

A
30
Q

What is the IEnumerator interface?

A
31
Q

What is the IDisposable interface?

A
32
Q

What is the IComponent interface?

A
33
Q

What is the IComparable interface?

A
34
Q

What is an exception, and what is exception handling?

A
35
Q

What would an example of a try catch block that prevents format and divide by zero exceptions?

A
36
Q

What is the try parse method and why would one use it?

A
37
Q

What is a try block?

A

A try block encloses code that might throw exceptions, as well as the code that’s skipped when an exception occurs.

38
Q

How does one simply catch an exception?

A
39
Q

What is the using statement?

A
40
Q

What are exception properties?

A
41
Q

Other exception properties?

A
42
Q

What would consoling different exception parameters look like in code?

A
43
Q

How would you throw an exception?

A
44
Q

What does an exception methods to string method return?

A
45
Q

What is the null-conditional operator?

A
46
Q

What are the is and as operators?

A
47
Q

What are nullable types?

A
48
Q

Was is the hasValue property used for?

A
49
Q

What is the null coalescing operator?

A
50
Q

What are eception filters and the when clause?

A