CentOS7 Firewall Firewall Common Commands

2023-01-01   ES  

Kotlin – open, final, abstract


In KOTLIN, all the classes are defaultfinal. If you need to allow it to be inherited, then you need to useopenStatement:

// This class has a `Open` attribute and can be inherited by other categories
open class People: Speakable{
    // `` Open` is implemented and covered, this method is also `Open`
    override fun say() {}
    // `Final` Method, must not be written 

 The method of
    fun sayHello() {}
    // `Open` can be inherited and covered
    open fun sayName() {}
}

Of course, you can also stop some methods from being written:


open class People: Speakable{
    // `Final` to modify a method that originally has the` Open` attribute, so that it can not be written again
    final override fun say() {}
}

In Kotlin,

The usage ofabstractis almost consistent with Java, and I will no longer be embarrassed. It is worth mentioning that when you use itabstractWhen the modifier is modified, you can ignoreopenmodifiers, because it isabstractmodified class defaults to beopenProperties.

modifiers Corresponding class members Note
final cannot be written All methods and classes in Kotlin arefinalattribute
open can be written Need to be clearly pointed out
abstract Must be written cannot be instantiated, the default hasopenProperties.
override How to write a superclass If it is not specified asfinal, then defaultopenattribute

The above form is only applicable to the base class. For the interface class, you basically don’t use itfianlopenabstract, because the interface class is defaultopen, and cannot be declared asfinal, if the method of the interface class does not have a function body, then it isabstract, but you don’t need to point out that he isabstract.

source

Related Posts

How to unify your mind in the real estate industry and take a key step in digital transformation

router set dmz steps

Related analysis — Apriori algorithm and FPGROWTH algorithm mining rules calculate the confidence between frequent items

UNI-APP Implementation Verification Code Login-Cloud News Stitch

CentOS7 Firewall Firewall Common Commands

Random Posts

C/C ++ function (find the root of the first -dollar equation)

Multi -object movement

[ITK Learning Notes] 1. Environmental construction

R language cluster analysis-KMEANS cluster analysis actual combat

2021.7.23 element type FY