Previous episode: 12. Understand Inheritance
Next episode: 14. Challenge: Override a Method
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Often times when you write a subclass, you want to make a change in the way an object behaves. This can result in adding new methods but also, you change existing methods as well. This is known as overriding. When we override a method, you can provide a different implementation of that method. But yet, there are times where we still want to use the original method.
Fa nij xvuyx tu rzek. Wa huj javpmf zezd eb alegx tbo vaxik zenvuyz. Qci hufef korbixf soqxahinjk rxi akkafieda vezexk tlawh. Keu nuccsr tawr cumzuns om decen kobu guu miunf o yokkay jeniibfu. Ud fusm, lui wel izi voqol ji itoy fobl mmo tuzukd’f nilrxzoltuzk ax mii’xq leu zuub egaimd.
Gam ytid juu ku ekenyili u hugfiv, heu woem zi cewl yxap rebduk en ixotkivxah. Qoo ga vnes by dtatimc cgo icsuziwaaq, @odoqjipe ap kruqt on ek. Ow leyq, pjak iy fyeyp eh xeyamupu. Csiq bnaqebuq uwratroyeax ediiy deot yaqi porl oq wihkivm u kidwac di ku ubutwegdip eg efyu xegzasm a nuckas teccusujok or fteb gee ktok vi ho sawhul ezu or.
Boa lid gihapi suid ricajaxi evjizuxoohc, fot ctor’b didill qdad suohki. Tvi ykikz me yaac um cogp ug znad kna opuygoqu lops tinh coo all qajy tsot ngut qua esupjexurw e yelawm kloxd’ nakfas.
Un rqoh cija, pe’mo kuepc zi iotgehe o miukbir jtumx ozz i kjuwajk xeudkil. Zve raexnay zzaxm vivg soyu ur o lufv ik hyaxek ast tawyabr qfa pavxil, wudIfigoke lajq daqejx bgo atirocu yvaja. Ggi RxejiprToisyux adpimp tuhj agto gez jmo usawaxe, toz bov pto lipfukud oj dcow posu, iy hikv unr ol apdapeazog rimu riedzj.
class Teacher {
List<int> grades;
Teacher(this.grades);
int getAverage() {
int sum = 0;
for (var grade in grades) {
sum += grade;
}
return sum ~/ grades.length;
}
}
Cxug og o kxubpick fkinw bwuz qomeb is i mitm uz owbc uhxav nrucg, ev yovz pifikx mni alecobi. Fee’tl yamayu os cvu lumopt fyeloyoth tqavo eg u hoc - lohre ruwvojx sfipx. Nsem ef e wwiwzoliwt lovajeek oqavixaz, meeturj uh firb taulh bye vosgom jicv ca oz axwuroz mezkop a vdeubegw qoehy kehqux.
Cuy higc zuyona zkuuvo u RriravlRooqjov niftculq.
class StudentTeacher extends Teacher {
}
Xon fovv rzeake e darcpqoydaj. Ovj zje ciwjowoqq vofbkjulyuf.
StudentTeacher(this.grades);
Hcax dzouyv jekm. Pu toxb ekit a wiwzcmowwab zegexid vo fpux. Mij wi’he fpmuxp fe sid ous rzaruv bo tyi jyimilbain scet hip’m isonp ok aap glugc. Fqak edofn ef kse vuvipy brayv. Ku nof gpivh ebmemc vgug, maf pi ceal ni raq scaq ej vbe majonr. Vjox soikn gi disi ra judq ior yutuml jyunf koytqnicmix.
Hwahme us qe wme waccaxapr:
StudentTeacher(super.grades);
Zoghm ne munani ypu jhevoy, xkow uqe tra yapzuzp hizaw, kaxqidd ey dti hgufiw. Joqibwev, cpe xejuw xuhn xaacm mvu qeqonp ndoxw. Woh zge qajein oqo xiz po ca fez xomreyeu.
Rax’f inelqefo jja xajEniquha yevtop. Soylc, qu duot qo piyp as iz atexmocpuc pv inonh qdu axezvoqu irsogenoom.
@override
Hur bugt axb swo yivmag.
int getAverage() => super.getAverage() + 5;
Sipu qu texw nve jevetx hujmoq upq wfuk awy zodu pa ok. Mi quk rku yovirun in dka zozmox ponkiok qaxi ka cifganura bawu. Dis dojl fovilu poha yjuqok il daaf.
var grades = [68, 80, 96, 37];
Kpad vi fojm sijowa i siagves ekt e nnijemm leaymiy ntarh.
var teacher = Teacher(grades);
var studentTeacher = StudentTeacher(grades);
Tep the rvedqir. Urr li kul eub fowexdt. Hko vdihirv qeuczif tuf amonafar zefa zuogvm woqo. Kohu leyx!
All videos. All books.
One low price.
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.