 Hey, everybody, it's Brian. Welcome to our 14th C-Sharp tutorial. Today, we're going to discuss inheritance. So let's just go ahead and make a few classes here. Let's say Add Class. And we're going to say Mammal. So we have a Mammal class. And then let's just add another class here. Let me shrink this down so you can see me actually typing these out. We'll say Feline. And then let's add another class here. And let's just call this Lion. So we have a Mammal, a Feline, and a Lion. Let's just kind of close these. And let's just focus on the Mammal class. Let's say Public. And we'll say Bull for Boling. Remember, Boling is simply a true-false on-off. It has Backbone. And Public, Bull has Hair because all Mammals have a Backbone and they have Hair. So that is our Mammal class. And oftentimes you'll see me put in the Access modifier for everything just so that it's crystal clear what I'm doing here. So let's close Mammal and let's actually open up Feline now. In our Feline class, what we're going to do here is we're going to say Public, Bull has Clause. Now, before we get too deep in this, let's actually jump into our program here. And let's just say Feline and see Feline equal New, Feline. You notice how Feline only has Clause. Well, Feline's also a Mammal. So we want to do what's called Inheritance, meaning we want to inherit the properties of another class. And this may sound confusing. And if you've got books on C-Sharp or other languages, they make it sound like you're just building a bomb out of spare parts like an episode of McGyver. If any of you are old enough to remember that. Inheritance is not hard and I wish people would not make it hard. Really? Just do space colon and then the name of the class you want to inherit, Feline Mammal. You have just inherited that class. Now, what does that mean? When you type C, Feline, you now have all the properties of the Feline class has Clause plus the Mammal class has backbone has hair. So really what you're doing here is you're taking two classes and kind of adding them together. You have your Feline class. Let's kind of go back here and review. Notice how it has Clause. You have your Mammal class, which has backbone and has hair and you're combining them by saying Feline inherits Mammal. So you're saying take the properties of the Mammal and add them to the Feline class. Now, why would you need multiple inherits? Why can't you just add those properties into the Feline? Well, let's say some genetic evolution happens and Mammals change. Well, dogs are also mammals, aren't they? So let's just go at class and let's say dog and we're going to inherit the Mammal class. So now dogs also have backbones and hair but they, unlike Felines, do not have claws. Well, technically dogs do have claws just not the way cats do. So what you could do with dogs is just say public bull can bark. Now, my daughter will argue that our cat barks but our cat is just really weird. It's like the exorcist cat, I swear. C-dog. Oops, let's make that lower case. So now you have C-Feline which has backbone, has claws, has hair and then you have C-dog which can bark but also has backbone and hair. That's why you'd use multiple inheritance. When you want multiple things, I'm sorry, not multiple inheritance, when you want to use inheritance, when you want multiple classes to inherit the properties of your class. So as you see, we have our Mammal class which is very nice and self-contained and we can put all the properties of a Mammal. They breathe, they're warm-blooded, they have hair, et cetera, et cetera, et cetera and then any other class can inherit those properties. Now, one catch or gotcha, if you will, is that some languages have what's called multiple inheritance. C-sharp does not. What is multiple inheritance? Multiple inheritance would be if you wanted to make a dog cat where you could say, you know, dog and you notice how it gives you a little squiggly thing and it says, you know, can't do that. What you're trying to do here is you're trying to inherit a Mammal and a dog. You cannot do that in .NET. There's no such thing as multiple inheritance. So that would be like taking a toaster or refrigerator in an airplane and all smushing them together. Now, to get around that, what you can do is called inheritance chaining. Inheritance chaining says, let's take our lion class here and let's inherit feline. So now the lion inherits feline, the feline inherits Mammal. So you have all those properties. Let's actually close dog out. Not a big dog fanatic here. So let's put these in order. Lion inherits feline, feline inherits Mammal. That's called inheritance chaining. So if we make a lion class, you can see how it has claws from the feline class and it also has a backbone and hair from the Mammal class. But because it's in its own class, lion, we can actually go in and add our own things. So like let's just say public void roar because well, lions roar. So now we have a function. Let's go back in here and I'm wondering if the video is probably chopping it off. Let's see if I can scroll down a little bit here. There we go. There's our roar. So as you can see, we have our lion dot roar. And if you highlight something, it says Mammal dot has hair. It's because it's telling you exactly where it's getting it from. Feline dot has claws. So that's inheritance and inheritance chaining. Very simple, very easy to work with and a very, very powerful feature. You will be using that a lot in your programs. Some fallbacks to inheritance are very simple. If something down the line, let's say you make this lion class which inherits feline, which inherits Mammal. And somebody goes in and changes this Mammal class. They say, Mammals don't have hair. Well, if your lion class is depending on that value or that variable or whatever it is, you just broke everything up the food chain here. So felines will start crashing, mammals will start crashing, et cetera, et cetera. So you want to make sure that when you allow inheritance in your classes, that you are very conscious not to change things that are going to break other classes that are inheriting you. And there's certain access modifiers and tricks you can use to keep classes from inheriting you. But we won't discuss those just yet. We're not there just yet. Anyways, this is Brian. Thank you for watching. I hope you found this tutorial educational and entertaining.