From the course: C# Practice: Interfaces and Abstract Classes

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Implement an abstract class

Solution: Implement an abstract class - C# Tutorial

From the course: C# Practice: Interfaces and Abstract Classes

Solution: Implement an abstract class

- [Instructor] The code challenge was to create an abstract class with an abstract method. Then override the method in the derived class. Before I show my solution, let's spend a minute talking about abstract class concepts. All classes need a base class. By default, it's system.object. So if you look at this class here on line 25, since I didn't specify a base class it derives on the default. However, it can be beneficial to create a common base class that multiple derived classes can share. For example, in the .Net framework, there is the stream base class which represents a stream. Then there are the FileStream and the MemoryStream classes which are more specific types of stream. So if we decided that we want to implement this as a base class, and you can see I'm using it up here on line 15, I have a TradingCard that by using this colon derives from Card. Now I've marked this class as an abstract class with this…

Contents