In this lecture, we'll talk about some of the big ideas behind inheritance and why It's useful. We'll start by answering the question, what is inheritance? Inheritance is a way that we structure our code so that multiple classes can share common fields, properties and methods. And if that were the end of the story, this wouldn't be very interesting. We could just make one class that contains all those shared fields, properties and methods. What really makes inheritance useful, is that we can have some of those classes implement class-specific state and behavior, fields, properties and methods, that aren't shared by the other classes. Let's take a look at an example. Here is UML for two classes, a car and a dragster. Now all cars have an engine, although with electric cars we should say a motor instead. So, something that provides propulsive force, and cars at this point still have wheels. And so those fields are common to all cars. And we also have properties and methods that would apply to any car. Now, a dragster is a specialized form of car that has a parachute. And so we might have a field that tells whether or not the parachute is deployed. And we might also have a method that says, here deploy the parachute. Not all cars have parachutes. So we shouldn't include that stuff in a car class, but we can include that in a child class. A dragster class without having to duplicate those common fields properties and behaviors or methods that apply to all cars, including dragsters. In the UML diagram, this arrow with an open triangle on the upper end indicates that the dragster is a child class of the car class. Let's talk about some terminology we use when we talk about inheritance. This diagram captures something called a class hierarchy. There's a hierarchy of classes that are structurally related to each other through inheritance. The top of this particular class hierarchy, the car class, is called the parent class. And the class that inherits directly from the parent class, the dragster class is called a child class. You may also hear these called a base and derived class, or a superclass and a subclass. But I'll pretty consistently talk about parent classes and child classes. A big idea behind this class hierarchy is that classes that are closer to the top or higher up in the hierarchy, are more general than the classes that are lower down in the class hierarchy. So in this example, a car is more general than a dragster. For another example, let's talk about humans. So we might have a parent class called human that has height and weight. So we could have fields that hold height and weight and properties that let us access them. And even methods that might affect them like, eat some food might increase your weight and exercising might decrease your weight. But we could have this parent class that pretty much applies to all humans. We might also have a child class for professors, and you may not realize this, but professors are humans also. But we also have some specialized state and behavior. For example, one of the state pieces that matters to professors is, how many papers do we have published, or even a list of the papers we have published. And we might have a method that says, publish a paper that would add that paper to the list of papers. Normal people don't actually care about published papers, but professors are special. So we're a specialized form of human. We inherit all the stuff from our more general parent class, but we also are specialized. We're more specialized because we have additional state and behavior to store. Okay, you should pause the video at this point, read this question, and decide which of these options actually applies as a reasonable answer to that question. It turns out that all four of those responses are reasonable responses for where inheritance can be useful to us. And we'll see examples of that as we continue through this course. I also realized that in the question, I talked about inheritance as an, is a relationship. Inheritance is an, is a relationship because we can say things like a dragster is a car, or a professor is a human. We can use that as a terminology, to talk about the relationship between a child class and a parent class. If you've heard about inheritance in software before, you may have heard of something called multiple inheritance. In other words, can a child class inherit from more than one parent class? And of course, in the real world we do, right? We inherit from both of our parents. And so you might think that it would be reasonable to also allow multiple inheritance in our software. While some languages allow multiple inheritance, C sharp doesn't. We can only have a child class inherit from one parent class. If you're curious about the motivation behind that limitation, you should look up the diamond of death problem that can occur with multiple inheritance. And you'll see why the C sharp language designers decided not to allow it. To recap, in this lecture you've learned that inheritance is structuring our code so that multiple classes can share common fields, properties and methods. While still allowing more specialized, class specific state and behavior in child classes. Another big idea was classes that are higher up in the class hierarchy are more general than classes that are lower down in the class hierarchy.