Experiment on your own with an exercise where static can help you make sure that there is only one Papa Smurf and only one Smurfette. Practicing with code can really internalize your understanding of static and set yourself up for using it in the future.
- [Instructor] I'd like to show you an exercise … that will help you use the keyword static in the real world. … And the example we're going to use involves Smurfs. … In case you're not familiar with the Smurfs, here they are. … These are four of the characters. … The girl is Smurfette. … We've got Papa beside her. … And then that's Handy Smurf and Clumsy Smurf next to him. … The thing about The Smurfs is, … there's only one girl called Smurfette, … and there's only one Papa Smurf. … I made over here a SmurfFactory. … And the way we're going to create these Smurfs is go to Smurf … and then you do createSmurf. … And then I can make some, like Handy. … Creating Handy over there … and then I can create a whole bunch more. … If I were to create all the Smurfs, … I'd be doing a lot of cutting and pasting. … But what I want you to do is see if you can make it so that … this code will only allow one Papa Smurf and one Smurfette, … which means that I should not be able to do this. … There's only one Papa Smurf. …
Released
11/11/2019This course was created by Madecraft. We are pleased to host this content in our library.

- What is an object in Java?
- Building Java classes
- Retrieving and updating variables with getters and setters
- Using the static keyword
- Understanding inheritance
- Diagramming code with UML
- Implementing polymorphism
Skill Level Advanced
Duration
Views
Related Courses
-
Advanced Java Programming
with Bethan Palmer1h 55m Advanced -
Docker for Java Developers
with Arun Gupta4h 37m Advanced -
Ethical Hacking with JavaScript
with Emmanuel Henri32m 40s Advanced
-
Introduction
-
1. The World of Objects
-
What is an object in Java?1m 13s
-
Prerequisites21s
-
Exercise files1m 44s
-
-
2. Inside Classes
-
The anatomy of a class1m 48s
-
The mighty constructor2m 34s
-
Construct a duck3m 18s
-
-
3. Getters and Setters
-
Using setters3m 13s
-
Testing with JUnit2m 16s
-
4. Static
-
What is static?1m 26s
-
Static runs a marathon5m 58s
-
Exercise: Static1m 29s
-
-
5. Inheritance
-
The mother of all objects1m 35s
-
6. UML
-
Drawing with UML2m 44s
-
7. Polymorphism
-
What is polymorphism?1m 24s
-
Polymorphism in action2m 11s
-
The purpose of polymorphism1m 17s
-
Implements vs. extends1m 59s
-
-
Conclusion
-
Next steps1m 30s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Exercise: Static