Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The statement we call it as a type
- // define type
- // every class has at least one type.
- // In Kotlin at least 2 types. show the example
- //just like an inherited class becomes subclass of a class.
- // The ype of subclass also becomes subtype of parent class type
- //show the example
- // also show non nullable type is a subtype of nullable type
- // val x: String = "John"
- //val y: String? = x
- open class Person(val name: String)
- class Student(name: String): Person(name)
- fun main() {
- //type
- val age: Int = 22
- val rollNumber: Int? = 4
- //subtype
- val student: Student = Student("John")
- val person: Person = student
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement