Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. // The statement we call it as a type
  2. // define type
  3. // every class has at least one type.
  4. // In Kotlin at least 2 types. show the example
  5. //just like an inherited class becomes subclass of a class.
  6. // The ype of subclass also becomes subtype of parent class type
  7. //show the example
  8. // also show non nullable type is a subtype of nullable type
  9. // val x: String = "John"
  10. //val y: String? = x
  11.  
  12. open class Person(val name: String)
  13.  
  14. class Student(name: String): Person(name)
  15.  
  16. fun main() {
  17. //type
  18. val age: Int = 22
  19. val rollNumber: Int? = 4
  20.  
  21. //subtype
  22. val student: Student = Student("John")
  23. val person: Person = student
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement