App/Android Native

KOTLIN BASIC III (OOP)

Agrafenaaa 2021. 9. 23. 18:16
  • Class, Object, Initializer
  • Shadowing

res -> a is 5

it is useful for decoupling the code from other parts of the system(names are bound to the current scope).

  • Get / Set

 

  • Data Class

  • Inheritance

  • Interface (abstract variable/method + it could inherit from another interface)

maxSpeed and drive should be implemented within inherited ones
override variable maxSpeed + method drive()
EvCar inherits from interface as a second child class
brake function works differently according to its class

  • Abstract class

- non-instanitiated

- subclasses could inherit from it

- the members are NON-abstract unless the keyword <abstract> is declared

 

🧡💜 Abstract class vs interface

  Abstract class Interface
Constructor O X
Multi-Inheritance X O
Field O X

  • Typecasting

 

 

 

 

 

 

 

 

Reference : Kotlin Android Tutorial / tutorialsEU / Youtube or Udemy