06.06.2013 Views

Computer Programming with GNU Smalltalk - Free

Computer Programming with GNU Smalltalk - Free

Computer Programming with GNU Smalltalk - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

102 <strong>Computer</strong> <strong>Programming</strong> <strong>with</strong> <strong>GNU</strong> <strong>Smalltalk</strong><br />

3.<br />

man3 := Man new.<br />

man3 setName: 'Canol Gökel'.<br />

man3 setAge: 24.<br />

man3 setMoney: 1.<br />

man3 setHandsomeness: 1.<br />

woman1 := Woman new.<br />

woman1 setName: 'Louise Stephney'.<br />

woman1 setAge: 26.<br />

woman1 setHonesty: 6.<br />

woman1 setGenerosity: 7.<br />

woman2 := Woman new.<br />

woman2 setName: 'Maria Brooks'.<br />

woman2 setAge: 32.<br />

woman2 setHonesty: 8.<br />

woman2 setGenerosity: 6.<br />

(man1 > man2) printNl.<br />

(man1 < man2) printNl.<br />

(man3 > man1) printNl.<br />

(woman1 > woman2) printNl.<br />

(woman1 < woman2) printNl.<br />

true<br />

false<br />

true<br />

false<br />

true<br />

"answer_5_3.st"<br />

Number extend [<br />

cubed [<br />

^self * self * self<br />

]<br />

]<br />

3 cubed printNl.<br />

27<br />

4. These two keywords are used to refer to the receiver object of the message, inside the class<br />

definition. Whenever we send a message to self or super keyword, the interpreter sends the<br />

message to the current object in context.<br />

The difference of super keyword from self is that when we send a message to super, the search

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!