C# Polymorphism / Interfaces / exception handling Flashcards
What is polymorphism?
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 would you demonstrate polymorphic behaviour?

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

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?

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

What is a concrete class?

What are some differences in abstract/concrete classes?

Can constructors or static methods be declared abstract or virtual?
No
What happens if you fail to implement all of a base classes abstract methods?

What are some main uses for abstract classes and methods?

What would the UML diagram of an abstract class hierarchy look like?
Abstract classes at the top and in italic.

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

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

How does the IS operator work?

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

What are sealed methods?

What are sealed classes?

What is an interface?

What is the difference between an interface and an abstract class?
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 do you create and use an interface?

When would you use an interface over an abstract class?

What is the naming convention for interfaces?
IName
eg. IPayable, IDrinkable
What is good practive for method naming in an interface?

How would a UML diagram look implementing an interface?

What does the syntax look like for creating an interface?

Hopw would you implement an interface to a class?

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

Can a class implement more than one interface? if so how?
Yes.
public abstract class Employee : IPayable, IListable
How would you use an interface to use a method and class polymorphically?

What is the IEnumerator interface?

What is the IDisposable interface?

What is the IComponent interface?

What is the IComparable interface?

What is an exception, and what is exception handling?

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

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

What is a try block?
A try block encloses code that might throw exceptions, as well as the code that’s skipped when an exception occurs.
How does one simply catch an exception?

What is the using statement?

What are exception properties?

Other exception properties?

What would consoling different exception parameters look like in code?

How would you throw an exception?

What does an exception methods to string method return?

What is the null-conditional operator?

What are the is and as operators?

What are nullable types?

Was is the hasValue property used for?

What is the null coalescing operator?

What are eception filters and the when clause?
