 Welcome to Intro to AP Computer Science for new AP teachers. In this video, we're talking about writing objects. Now, we've done a little bit with this already. We've actually created some classes. We've created some objects. We talked about setters and getters. But now we're going to talk about some of the other types of methods you might want to create and talk a little bit about constructors as well. So, we're going to look at static versus non-static methods. There's just a quick, you know, explanation of that there is a difference or different types of methods. I will get more into that later. In this case, we're looking at non-static methods. So, these are methods that, as you'll see, are attached to objects. Talk about the default constructor, which we've actually been using. We just didn't really explain that we were using it. Talk about how to do non-default constructors. The two-string method, which is kind of important, and a little quick introductory exercise. So, static versus non-static. So, static methods and attributes are attached to the class. So, we've seen that before within the recursion unit in the non-static or in the static methods unit as well. We've gone over these things. So, for example, you know, number of students. Okay. So, the class has a certain number of students. The number of students is not a quality of an individual student. That's the example I gave, I think previously. Non-static methods and attributes are attached to the objects. So, for example, if you have five students, those five students could be in five different grade levels. They could be the same grade level, but not necessarily. The grade level of a student is a quality of that student, not all of the students collectively. That's kind of how I try to explain it. So, non-static method format. It's very similar to static methods. So, they may or may not have a return type. They may or may not have arguments. But the big difference is you'll see here, there's no static here. So, public or static methods had public static type method args. This one just has public type method args. And again, outside of the static part, okay, return type, no return type, or you know, return type or void, arguments or no arguments. So, there's four possibilities that are just like with the static methods. So, here's an example I like to give. So, a person may say a greeting. So, public void say greeting because we're not returning. And system.out.printline high. My name is this.name plus period. So, the example in the book is ironman.say greeting. And you know, hi, my name is Tony. So, this is what that particular object would say. Now, if it was Captain America, Captain America dot say greetings. Hi, my name is Steve. So, you kind of get the idea there. Because each object, each person in this case would have their own name. Now, people can have the same name. We know that. But generally speaking, names tend to vary. Default constructor. Okay, so again, I haven't really talked about this before. Maybe mentioned it in passing. So, thus far, we have instantiated our objects. And then, let's just say changed their attributes like so. So, class says the class, the object name equals new class. So, you notice there's this is empty. And then we did object dot attribute equals value. In the last unit, we learned object dot set value set value. We use our setters instead. So, however, we can create our own custom constructors when we write our classes. So, just like we did with overloading static methods, we can do the same. So for example, class type attribute, this dot attribute equals attributes. So, for example, playing card. So, we may have string name and string suit. So, this dot name equals name, this dot suit, suit. Now, we could do, you know, just card without the arguments, and then do, you know, card dot set name, card dot set suit, that's possible as well. But what we can do is to shorten that, we can just do it when we create the object. So, the constructor is a special method that is called when the object is created when it's instantiated. So, you notice there's no public here. It's just the same name as the class. Notice it's capitalized as the class is capitalized as well. So, it's a special type of method. Now, if you don't have a constructor, if you didn't put one in, there's a default constructor that takes no arguments. And that's what we've been using all along. But finally, we're learning how to create our own. So, as I mentioned, just like with other methods, we can overload that constructor. So, we could have a constructor that has string string int. And we can do that. Or we can have a characters has string and string, and then it would call this. So, depending on the method call, it will call the correct constructor based on the signatures that goes back a few units. All these concepts hopefully will be familiar to you and your students. And that, you know, we keep reinforcing them every couple of units. Two string method. This is a special method that is called when an object is printed. So, the format is public string to string. And it returns, this is just going to be a blank line. This, it returns some sort of string. So, when I do system.out.print or system.out.print line, whatever goes here is what's going to get printed on the screen. So, for example, back to my card class. So, public string to string will return this name plus this suit. So, my constructor, card, card equals new card. And it's the ace of spades. You probably guess why I chose that one. And then, if I do system.out.printlin card, it will print a, you'll see an a and a spade on the screen. So, yeah, you need to know that. So, our interesting exercise. So, is choose an object and just what we've done all along, come up with three attributes of different types, and write three different constructors using any combination of attributes. And then instantiate some objects using the new constructors. And at that point, you can do your setters and getters, and see if you can print out that information. So, this is a bit more, you know, hands-on to do some coding. You can do it, you can do it in paper, you can do it in pairs, you know, you know, your students. Some students prefer to work alone. Some students prefer to work with a partner. My students love working with partners. So, I do that that way. And your kids. Yeah, I think. Oh, okay. So, just quick review. So, we did, we looked at static versus non-static methods. The non-static method format basically, same static minus the static keyword. Talked about the default constructor, finally, even though we've been using it all along. Talked about non-default constructors and overloading, just like we did with static methods. Looked at the two string method, which is very, very important. And hopefully a little introductory exercise that'll help you kind of introduce and cement some of these ideas in your students' heads. Thanks for watching. Take it easy.