Review Questions
1: | Consider an Animal class from which the Dog, Cat, and Duck classes are derived. Suppose that any Animal can make a sound. Where would you locate the Sound method? Would you provide an implementation for this method or declare it abstract? Why? |
2: | If the Sound method of the Animal class was declared abstract, would you be able to instantiate an object from this class? Why or why not? |
3: | You want to implement a Sound method in each of Animal's three subclasses and call these three methods polymorphically. Which keywords would you use to declare the Sound method in Animal and in the three subclasses to allow this scenario to take place? Write the method headers in the Animal class and the three subclasses. |
4: | What's wrong with the following ... |
Get C# Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.