Kotlinlearncs.online LogoJava
Return to List

Homework: Simple Object Method

Created By: Geoffrey Challen
/ Version: 2020.9.0

Let's continue our exploration of Kotlin objects, which combine state and behavior. We've seen how to create an object that stores a single value. Now let's see how to create an object that implements a single method acting on stored data. Again, this is not representative of the true power of Kotlin objects, but we're just getting started!

Create a class called Simple. Simple should store a single Int value which you can initialize to 0. It should also provide a public method called squared that takes no parameters and returns the stored value, squared.

Related Lessons

Stuck? You may find these lessons helpful: