Читать книгу Programming Kotlin Applications - Бретт Мак-Лахлин, Brett McLaughlin - Страница 19
KOTLIN IS OBJECT-ORIENTED
ОглавлениеAt this point, most books and tutorials would have you put together a simple “Hello, World” program. That's all well and good, but the assumption here is that you want to get moving, and get moving quickly. For that reason, the logical place to begin with Kotlin is by creating an object.
An object is simple a programmatic representation of a thing. In the best case, that thing is a real-world object, like a car or a person or a product. For example, you could create an object to model a person like this:
class Person { /* This class literally does nothing! */ }
That's it. You can now create a new variable of type Person
like this:
fun main() { val jennifer = Person() }
If you put all this together into a single code listing, you'll have Listing 1.2.