What is the difference between 'open' and 'public' in Kotlin?

后端 未结 6 1884
面向向阳花
面向向阳花 2021-01-03 19:26

I am new to Kotlin and I am confused between open and public keywords. Could anyone please tell me the difference between those keywords?

6条回答
  •  北海茫月
    2021-01-03 20:05

    All classes, methods, and members are public by default BUT not open

    Keyword open in kotlin means "Open for Extension"

    means if you want any class to be inherited by any subclass or method to be overriden in subclasses you have to mark as open otherwise you will get compile time error

    NOTE: abstract classes or methods are open by default you do not need to add explicitly.

提交回复
热议问题