Can Class name be used as type of variable declaration

class SmartTvDevice : SmartDevice() {
}

class SmartHome(val smartTvDevice: SmartTvDevice) {

}

I have a question in the above syntax where Val smartTvDevice is mentioned. After colon the name SmartTvDevice is a type for variable. But I learned only these types in kotlyn docs. String, float, Boolean, int. Is class name can be used to for type? Thank you

Yes. Classes define their own types. I’d urge you to check out the documentation, especially the Classes section

1 Like

Also see the StackOverflow question What is the difference between types and classes in Kotlin?, which covers this. (Disclaimer: one of the answers is mine :​-)

In particular, while many classes are types, some aren’t (e.g. generic classes, which need type parameters to be specified), and some types aren’t classes (e.g. interfaces, or classes with a trailing ? indicating a nullable type).

1 Like