Navigation:  Tutorials > Beginners Guide to Smalltalk > Programming in Smalltalk > Creating a class >

Adding instance variables

Previous pageReturn to chapter overviewNext page

Now let's go back to consider the data that each instance of our Animal class must hold. We mentioned before that we need to be able to hold the name of the animal as a String and we will therefore need an instance variable to do this. So, let's add an instance variable called name. Using the mouse, place the text insertion cursor in the text string that immediately follows instanceVariableNames: and type the variable name.

Object subclass: #Animal

       instanceVariableNames: 'name'

       classVariableNames: ''

       poolDictionaries: ''

 

In order to commit this change into the image simply type Ctrl+S or choose Accept from the Workspace menu.

Congratulations, you have just added your first class to your Dolphin image. You can change the class definition at any time simply by modifying it in the Class Definition pane and accepting the change. Now might be a suitable time to save your image.