Navigation:  Tutorials > Beginners Guide to Smalltalk > Classes and Methods >

Private Methods

Previous pageReturn to chapter overviewNext page

Now select #x:y: in class Point (Point>>x:y:).

x: xCoord y: yCoord

       "Private - Set the x and y coordinates of the receiver.

       Primarily intended for instance creation. Answer the receiver."


       x := xCoord.

       y := yCoord


This shows the definition of a method with two parameters. Note also, that there is no explicit statement returning a value so this means that the method will answer the receiving point when it completes. Also interesting is the fact that, in the comment, the method is marked as being "Private". Some methods are written to be of use only by the original programmer of the class itself and are not expected to be used generally by others. These methods are said to be private to the class and are indicated as such in their method comments.

Tip: unlike many other programming languages, Smalltalk does not enforce this idea of method privacy. It is perfectly possible for you to call any private method at any time. What the method author has indicated is that this may not be a good idea, either because the method might have unusual side-effects, or because the method is not guaranteed to be present in future implementations of the class.