From the course: Programming Foundations: Object-Oriented Design
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Instantiating classes - Python Tutorial
From the course: Programming Foundations: Object-Oriented Design
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…
Contents
-
-
-
-
-
-
-
(Locked)
Creating class diagrams: Attributes2m 23s
-
(Locked)
Creating class diagrams: Behaviors3m 9s
-
(Locked)
Converting class diagrams into code4m 29s
-
(Locked)
Instantiating classes3m 38s
-
(Locked)
Class with multiple constructors2m 29s
-
(Locked)
Static attributes and methods4m 19s
-
(Locked)
Challenge: Jukebox class diagrams1m 18s
-
(Locked)
Solution: Jukebox class diagrams5m 5s
-
(Locked)
-
-
-
-