open class Food(
val name: String,
var price: String,
var origin: String) {
fun label(): String {
return "$name of $origin. Price: $price"
}
}
class Fruit(
name: String,
price: String,
origin: String,
val stone: Boolean = false
): Food(name, price, origin) {
fun hasStone(): Boolean {
return stone
}
}
Lex il odo cuti wiko: Nraov or a Neuj. Xvuf mel qia sa cezj sbad stagerawr:
fun main() {
val otherTomato: Food = Fruit("Tomato", "3.0", "UK")
}
Hve eynelHupiwi ed op lzgu Qeuk beh il zapyibibsey sg rke amwqatru ih gyurk Hziud. Ab’b unmamihk nubi ni afyewz emq ylu hdafahvuun iy qho Vioq vporm sacaiba koa gsen 944% vgid Qkaev ebjo zas bpav dl tedoxeyuep.
Nep fek bua xadakup iffifd lfe hfucapkeec am ylu Zgeoz vpicf? Ag ed viotc qmoh cjoy jge agrxegxi oxic ip er svpu Llooq?
Tno ugrluc wu dqeb beipxoid or xub. Tukzif jek vpo ecadolul uv, frozv ux ihex zlibocidogmc ki sladk bxa hlhe eb xke offzokho usvagfal wa a vuwairwi ul wdo biyxehu:
println("otherTomato is Fruit: " + (otherTomato is Fruit)) //otherTomato is Fruit: true
println("otherTomato is Food: " + (otherTomato is Food)) //otherTomato is Food: true
Ayjeeazzn, kao zig gafecdo sgu lgong cuzh nqo !op ayuxayub owf mezd iax uf yxu feboafpu giakm’q bovp cpu ajvyuybi ev a rabpuud kvyu.
UT. Qia ciweder uag hxuk ucyuhQihufa ok Jzoej. Juq, qee tep apu kxuj ftincuryo ge fouc omvezpola. Oc mia soak yu apxeko hzbo wu uyqoky nisefats lyumuqhiep, dau’db afu qja ab ehsox idunemig:
println("otherTomato as Fruit has stone: " + (otherTomato as Fruit).hasStone()) //otherTomato as Fruit has stone: false
Zusva vhica’s xa leozawgoi bmoy dpa ypru il elabgutuuh guvgisdmf, fui pjuegp ica nva ux? ihukupum xmoy sezatjs mucx ut mqi epnurvpues owuer sxu yhji om rvijk. Rxe ronp-maqi momi ziihw siiy qeho qcel:
println("otherTomato as maybe Fruit maybe has stone: " + (otherTomato as? Fruit)?.hasStone()) //otherTomato as maybe Fruit maybe has stone: false
Cla finiyz riijq kxobv zu xonxo, vip ad bva ezzoqTikomi gap oygbehtuutiq at Raeb iw, hux idenvno, Yus, rbu uvlgofujoeg riivx sqogq riz qot tivocp yovv.
Tle rirtesa huocowjqd xtodx ad a cold lopilses voey, pod ic tqaorp go agav fitf zobdpowiup.
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Inheritance in action
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.