Content Archived

This content is no longer current. Our recommendation for up to date content:

Working with Classes and Inheritances in the .NET Framework Class Library - 16

Play Working with Classes and Inheritances in the .NET Framework Class Library - 16
Sign in to queue


We've been looking at working with classes in the two previous lessons. The hope is that by better understanding how classes work, you'll gain an appreciation for how classes are utilized in the .NET Framework Class Library (FCL). In the FCL, child classes often inherit basic functionality from their parent classes. In fact, all classes ultimately inherit from a single base class, System.Object. This lesson continues to teach concepts about classes (specifically, in this case, inheritance) by showing you how to utilize inheritance in your own custom classes. You'll learn about overriding virtual functionality, abstract base classes, sealed classes, and more.

Download the source code for Working with Classes...


C#, Visual Studio



The Discussion

  • User profile image

    Inheritance being one of the four pillars of OOP, I was hoping that this beginner's series will also touch on the others such as Abstraction, Ecapsuation, and Polymorphism. Can we please get these added as one (or two) more video(s)?

  • User profile image

    Hi @techieg ... thank you for you comments.  The content of the series was discussed with the Channel 9 team before I set off to record it and they wanted to keep the scope of this series aimed at helping absolute beginners learn just enough to get them started building applications in C#.  About 6 years ago I created some content that did include the topics you mention, however the goals of THIS series were different this time around.  Even in this particular video you'll see that I talk about inheritance in the context of understanding how it is used in the .NET Framework.  Often throughout this series I attempt to point students to learn more about Object Oriented Programming using other videos and articles on Channel9 / MSDN, the web and my own site.  I explain a class as merely a "container for your methods and properties".  As someone who already knows some of the terms you reference, you undoubtedly know a proper examination of Object Oriented Programming extends beyond the C# language.  True, in this video I demonstrate HOW to create classes that inherit from others, but the intent is that it is purely to be used for informational purposes to help you CONSUME FCL classes or understand the inheritance tree as displayed in the MSDN help. Actually USING inheritance (successfully) in your applications would require a deeper discussion of layers, particularly the role and value of the business layer (or better yet, the "domain model").  Perhaps a "Object Oriented Fundamentals" or "Application Architecture Fundamentals" is something the Channel 9 team would consider in the future, but they have not approached me personally about it.

    I suspect that if you are aware of the terms "abstraction, encapsulation and polymorphism", you were probably not the intended audience for this series.  Smiley  (That was meant as a compliment.)

  • User profile image


    I am very familiar with OOP, and am watching these videos to learn the basics of C#, as I have already been taught C++ and Java. I am following the videos line of code by line of code of visual studios for each video. Up until now, I have not had any problems. Though, for this video, when I write the code for the Truck sub class, I receive the error of Inconsistent accessibility: base class SimpleClasses.Vehicle (I named my "car" class "Vehicle" instead)is less accessible than SimpleClasses.Truck. I saw that Bob did not experience this error.

    Being new to C#, I was wondering if anyone could give my any guidance to this error. I set my new project up just like we have been for all the previous videos, and to reiterate, my code is exactly what Bob's is. I tried putting Make, Model, Year, and Color variables into constructors for both the Vehicle (car) and Truck class, but that doesn't seem to fix the compilation error.

    Thanks for any help!

  • User profile image

    @Ryan:  Sorry for the very late reply!  (I was working on another series for Channel9 ... coming soon!)  I think the fix is simple ... you're missing the keyword Public on either the Truck or Vehicle class.  Omitting the access modifier on a class (i.e., public, protected, private, etc.) will make it private by default.  Hope that helps!

  • User profile image

    Thanks for your video... It is useful for me as a beginner.

  • User profile image

    Hi, great videos.

    If I put override on the PrintMe() i get:

    Error 1 'UnderstandingInheritance.Truck.PrintMe()': cannot override inherited member 'UnderstandingInheritance.Car.PrintMe()' because it is not marked virtual, abstract, or override

    But if I remove it works, but I get:

    Warning 1 'UnderstandingInheritance.Truck.PrintMe()' hides inherited member 'UnderstandingInheritance.Car.PrintMe()'. Use the new keyword if hiding was intended.

    But it still works. Can you explain?

  • User profile image

    Figured it out... Had forgot the virtual in the Car method. But even though, it still works without virtual and override. Or at least I get the same result.

Add Your 2 Cents