Instantiating an Object
Once you have a class, you can then instantiate it. So in this example on-screen right now, you have
class Point, and you’re passing, so it’s just a blank class. And you take the name of the class, and you add some brackets next to it. Just a quick note on terminology here.
This instantiates the class. You can do this various times, and it will create two instances. The default representation of the class, which is the string between the two chevrons (
<>), says that the
Point object is at this long number, which just refers to its memory address. And as you can see, these two
Point instances have two different addresses indicating that they are two different instances of the
Carrying on from before, you have your
Cat class. You evaluated just the
Cat part of the class, but if you were to take
Cat and add the two brackets as if you were calling a function at the end of it, then you get your
Cat object with the memory address.
01:25 And if you do that again, you’ll get a new one. And you can do that as many times as you want. That’s the beautiful thing about classes is that you can create many instances of the class, and they’ll all share some attributes, but they’ll all be unique in the sense that they live at separate places, and so you can operate them independently if you want to.
01:49 Empty classes like this do have their uses just as a sort of name for things, but in general, you’ll be wanting to add things to your classes: attributes, methods, all these things are going to come up soon.
Become a Member to join the conversation.