-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThisAndSuper.kt
38 lines (30 loc) · 1.01 KB
/
ThisAndSuper.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* This AND Super
* you can access function or variable on the class itself with THIS
* you can access funciton or variable on Parent Class with SUPER
*
* Note:
* all inheritance rules is applied too, so careful when accessing variable and function
*/
open class SuperClassTest(){
protected var super_variable_protected:String = "This is super protected variable"
fun getProtectedFunction(){
println(this.super_variable_protected)
}
}
open class ChildClassTest(): SuperClassTest(){
protected var local_variable_protected:String = "This is local protected variable"
fun getProtectedParentFunction(){
println(super.super_variable_protected)
}
fun getLocalVariableFunction(){
println(this.local_variable_protected)
}
}
fun main(args:Array<String>){
var super_class = SuperClassTest()
var child_class = ChildClassTest()
child_class.getProtectedParentFunction()
super_class.getProtectedFunction()
child_class.getLocalVariableFunction()
}