 Everybody, it's Brian, and this is our 20th video. Today, we're going to discuss classes. And we're actually going to stretch this out over a couple videos, because this is a complex topic. And it's the foundation of object-oriented programming. You hear that term thrown around a lot, object-oriented programming. Well, today you're going to learn what that is. Let's start by making a class. Call it cat. And that's it right there. That's the basic class. Starts with the class keyword, followed by a name that identifies that class. Our code block with a semicolon ending. Now, if you're coming from C-sharp or Java, you must remember to put that semicolon there. You're going to have all sorts of error messages when you try to compile. Now, what is a class and what is an object? Well, this is a class. Class is a template or a blueprint. We're actually defining something. An object is an instance of that class. I know those terms get thrown around an awful lot, and they get kind of confusing, and some people actually mix them up and get them just dead wrong. And I know I'm probably going to get some hate mail saying that I'm getting it dead wrong, but really, OK. The class is the template. The instance of that class is an object. So let's actually go ahead and make an object here. Very simple, just like we declare other variables, the type and the variable name. And now we want to throw some items in here. Let's just say int age. We're going to give our cat an age. This is where we need to stop, and I need to discuss access modifiers with you. What is an access modifier? Well, classes are special in the sense that you can have different levels of access, meaning you can have it so that the entire world can access it or just that class or just inherited objects. Today, we're going to cover public and private. Go ahead and type public and enter. Now, everything by default is private. So right here is private. Right here is public. Now, what does that mean? That means only this class can access these variables. To kind of solidify that fact, we're going to say mcat.age equals 17. Let's try to compile that and see what happens here. Notice there's an error message, and it says cannot access private member declared in class cat. You also may have noticed that when we're mucking around here, there's a little lock icon that tells you that you can't access that. We know it's there, but we can't access it. We don't have permission. It's only accessible inside the cat class itself. So we have the public access modifier. And what this does is allows us to make things public, so you can access them outside of the class. So by simply moving the variable to the public area, you see that this suddenly compiles and works as expected. Now, that's actually bad form. You don't typically want to do that. What you want to do is build what's called a getter and a setter. And if you're from Java, you're familiar with that. So you'll say int get age, and we'll just return age. That's a getter. You're just going to get the variable and return it. And a setter, as you might have guessed, you are going to set the variable. Oops, we kind of missed a step here. I misspelled the. That's classic. So we're going to say age equals the age. So that's a getter, where you get the variable, and a setter, where you set the variable. Now, instead of cat.age, you say cat.setAge. And if your IntelliSense hasn't quite caught up, don't worry. We know what we're doing. Maybe. OK. And then cout. And let's compile this and see it run. You see, sure enough, there's 17. Now, what good is this? We could have accomplished all this with variables and the like down here. Well, let's say we have multiple cats. And let's say we have a boy cat and we have a girl cat. So now we have multiple cats here. And let's say the boy cat is 17. And let's say the girl cat is only 10. Now you start to understand the power that object-oriented programming really gives you. Before, all the tutorials we've been doing is all functional programming. Now, as you can see, you've created a template using the class. And you can create instances of that template. So now we have two separate objects here, a boy and a girl. And you can set their individual variables differently. So the template acts differently. It's called polymorphic programming. The template acts differently depending on how you want it to work. It's a really, really cool concept. Sure enough, there's 17 and 10. So that, in a nutshell, is how to build a class. We're going to get into these a little more in depth over the next couple tutorials. Like I said, I don't want to over-and-endate you. Play around with this example. Get a real feel for it. Definitely understand the difference between private and public. If it helps you even actually type in private, that way you understand that, by default, everything's private. And you have explicitly say public in order to make them visible to the outside world from your class. So this is Brian. I hope you found this video educational and entertaining. And thank you for watching.