Kotlin Visibility Modifier - open, private, protected, internal (the summary of the kotlin terms)

2022. 5. 28. 00:01카테고리 없음

1. Public and Private

kotlin's default : public.

user define : private.

private == only available inside of the scope

 

if the private value is defined, the value can be used inside the particular class or the specific scope where the value had been defined.

SUM : the useage of the private value inside of the class
derived class : X
main function : X can not use, unvisible

 

2. Protected

protected== linked thing.

 

 if the value inside of one class is protected, then only derived classes and methods can use that value. Since the derived class could inherit the properties of the class, it is possible to be linked with the protected value. However, on the main function, protected value could not be used since it is not connected or derived, remaining private.

SUM : the useage of the protected value inside of the class
derived class : O able to override
main function : X can not use, unvisible

 

3. open

able to inherit, override

 

4. internal

internal == inside of the file

 

 if the value is internal, it can be used as the public value only if it is inside the scope of the file. 

SUM : the useage of the internal value inside of the class
derived class : O
main function : O can use, visible