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?