Hauv Java, kev sib raug zoo ntawm Has-Ib qhov tseem ceeb txhais tau tias piv txwv ntawm ib chav kawm muaj kev siv rau lub sijhawm ntawm lwm chav kawm lossis lwm qhov tshwm sim ntawm chav kawm zoo sib xws. Piv txwv li, lub tsheb muaj lub cev muaj zog, ib tug canine muaj tus Tsov tus tw, thiab lwm yam. Nyob rau hauv Java, tsis muaj xws li watchwords uas ua rau ib tug Has-A kev sib raug zoo.
Kev sib raug zoo hauv Java yog dab tsi?
Hauv Java, Has-A kev sib raug zoo tsuas yog txhais tau tias piv txwv ntawm ib chav kawm muaj kev siv rau ib qho piv txwv ntawm lwm chav kawm lossis lwm qhov piv txwv ntawm tib chav kawm. Piv txwv li, lub tsheb muaj lub cav, tus dev muaj tus Tsov tus tw thiab lwm yam. … Tab sis peb feem ntau siv cov ntsiab lus tshiab los siv Has-A kev sib raug zoo hauv Java.
Yuav ua li cas muaj kev sib raug zoo hauv oops?
In OOP, YOG-Kev sib raug zoo yog qub txeeg qub teg. Qhov no txhais tau hais tias, cov chav kawm me nyuam yog ib hom niam txiv chav kawm. Piv txwv li, txiv apples yog txiv hmab txiv ntoo. Yog li ntawd koj yuav ncua txiv apples.
Kev sib raug zoo twg yog qhov muaj kev sib raug zoo ntawm cov khoom?
Association is a "has-a" type relationship. Lub koom haum tsim kev sib raug zoo b / w ob chav kawm siv los ntawm lawv cov khoom. Kev sib raug zoo tuaj yeem yog ib qho rau ib qho, Ib qho rau ntau, ntau rau ib thiab ntau rau ntau.
Qhov txawv ntawm yog ib thiab muaj kev sib raug zoo hauv Java?
Ib IS-A kev sib raug zoo yog cuab yeej cuab tam. Cov chav kawm uas tau txais qub txeeg qub teg hu ua sub classes lossis cov chav kawm me nyuam yaus. Nyob ntawmNtawm qhov tod tes, HAS-A kev sib raug zoo yog kev sib xyaw. Hauv OOP, IS-A kev sib raug zoo yog qhov qub txeeg qub teg.