From the course: Object-Oriented Programming with Java

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Exercise: Static

Exercise: Static

- [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…

Contents