O'Reilly logo

Professional C# 6 and .NET Core 1.0 by Christian Nagel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4 Inheritance

What’s In This Chapter?

  • Types of inheritance
  • Implementing inheritance
  • Access modifiers
  • Interfaces
  • is and as Operators

Wrox.com Code Downloads for This Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/professionalcsharp6 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • VirtualMethods
  • InheritanceWithConstructors
  • UsingInterfaces

Inheritance

The three most important concepts of object-orientation are inheritance, encapsulation, and polymorphism. Chapter 3, “Objects and Types,” talks about creating individual classes to arrange properties, methods, and fields. When members of a type are declared private, they cannot be accessed from the outside. They are encapsulated within the type. This chapter’s focus is on inheritance and polymorphism.

The previous chapter explains that all classes ultimately derive from the class System.Object. This chapter covers how to create a hierarchy of classes and how polymorphism works with C#. It also describes all the C# keywords related to inheritance.

Types of Inheritance

Let’s start by reviewing some object-oriented (OO) terms and look at what C# does and does not support as far as inheritance is concerned.

  • Single inheritance—With single inheritance, one class can derive from one base class. This is a possible scenario with C#.
  • Multiple inheritance—Multiple inheritance allows deriving from multiple base classes. C# does not support multiple ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required