Bu dersimizde java dilinde olduğu gibi kotlinde de bulunan interface kavramının ne olduğundan ve kotlin dilinde nasıl kullanıldığından bahsedeceğiz.
Bu derste yazılan kodlar aşağıdaki gibidir.
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 39 40 41 42 43 44 45 46 47 48 49 50 51 |
interface operasyon { fun topla(s1:Int, s2:Int){ println("topla: ${s1+s2+s1}")} fun bolme(s1:Int, s2:Int){ println("bolme:"+ s1/s2)} } class KullaniciOperasyonlari : operasyon{ override fun topla(s1: Int, s2: Int) { println(s1+s2) } override fun bolme(s1: Int, s2: Int) { println(s1 / s2) } } class YoneticiOperasyon : operasyon{ override fun topla(s1: Int, s2: Int) { println(s1+s2+10) } override fun bolme(s1: Int, s2: Int) { println(s1/s2 + 10) } } class EmreOperasyon:operasyon{ } fun main(args:Array<String>){ var user:KullaniciOperasyonlari=KullaniciOperasyonlari() user.topla(5,8) var yonetici = YoneticiOperasyon() yonetici.topla(5,8) var emre=EmreOperasyon() emre.topla(5,8) } |
Hocam devamı gelmeyecek mı ?