From the course: Programming Foundations: Object-Oriented Design

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Instantiating classes

Instantiating classes - Python Tutorial

From the course: Programming Foundations: Object-Oriented Design

Start my 1-month free trial

Instantiating classes

- When we write the class for a spaceship in our video game, we're creating the blueprint to build the spaceship. Now, the blueprint itself isn't a usable object, but from that class, we can instantiate or create one or more instances of that type of spaceship object. And to do that, many object-oriented languages use the keyword new. In Java, we'd say Spaceship then the variable name myShip equals new Spaceship with open and close parenthesis. And that instantiation line would be identical in C#. C++ looks very similar to Java and C# except it's using the asterisk to indicate a pointer. Don't get caught up in syntax here, these are just some examples to show how languages differ. Ruby is unique in that it puts the keyword new after the class name. But not all languages use new. In Python, it's simply myShip equals Spaceship, and Swift uses the keyword let to assign the newly instantiated Spaceship to the variable named myShip. When we use one of these instantiation statements, shown…

Contents