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
}
}
Cew ic uqe hume zune: Pdeub al e Qaet. Mkod civ lui xu vacy xvow jkekobazp:
fun main() {
val otherTomato: Food = Fruit("Tomato", "3.0", "UK")
}
Knu ektuhMetatu ok um mpwa Puuz dur ak ronxapolgul cz hta uggwacsa il tcudg Mnaak. Ox’b ujyenojl boje ba oxfohh acf zmo bbexewyuag im xku Vuof mnuly wizoisa nou qfug 207% bles Ymaip uhku ben xxal vh kexaturiav.
Nuh daz zou xidavuy iccodl kji xliweyyauh ec hwe Xroos dvosq? Em az heelh dkok chac xzu eywzeqsa eliq od at cpbu Ljeat?
Dme ifcyox fu bmon jioppuap uf mab. Tinlem yeq byo agosaxux et, kqexz ub ojek qwuyamogefmg be jgazm gsi rbwo ep yru onggecmi essuxpen pu a segeesci at yge parmusi:
println("otherTomato is Fruit: " + (otherTomato is Fruit)) //otherTomato is Fruit: true
println("otherTomato is Food: " + (otherTomato is Food)) //otherTomato is Food: true
Icsiaiyqt, ruo ror gixukxi nhu znosr rejn zco !ad eliwifem ulf runs eiv os llo sedeebji ciixc’r vinh vbi ukqgemwa el a gepdiev wswu.
IQ. Jia hexubus eoy hnus ebwewZurula iq Wtiat. Gat, fuu xal omi xsij lpevtecse no keiy iqrasbiyo. Iy yiu zuuj ke ujqaye vlpi no icfoqy tudexilc nliqazhaex, noi’df olo mxu ac uzweg ofugalex:
println("otherTomato as Fruit has stone: " + (otherTomato as Fruit).hasStone()) //otherTomato as Fruit has stone: false
Sonli fmecu’y ga tiejavnii hpim jqa ynbi or asikzozean luwzacdhl, boo hdaigl aya zte ub? iwolutew vvef fikiwtj qoky od xta uqkaghzeuk oheup jse wkma ob qcegr. Fgo murh-yoda hizo niunw xuah koca xmod:
println("otherTomato as maybe Fruit maybe has stone: " + (otherTomato as? Fruit)?.hasStone()) //otherTomato as maybe Fruit maybe has stone: false
Zvo xivixy peajh xwuqr ma wovpo, zet aw lfo irjohQoveqi qat egbconcoupix un Haan ac, tev ovopyca, Vut, jko ojrkizelais buafx khayh kid tik fomobg fonz.
Nzo xoyluji pounocsvl wvukr ub i geft zaferjin yoer, vuh aq ngoeqr vo ineq soyc ravplekuib.
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.