Lub hom phiaj ntawm kev nkag mus hloov pauv hauv Java yog dab tsi?
Lub hom phiaj ntawm kev nkag mus hloov pauv hauv Java yog dab tsi?

Video: Lub hom phiaj ntawm kev nkag mus hloov pauv hauv Java yog dab tsi?

Video: Lub hom phiaj ntawm kev nkag mus hloov pauv hauv Java yog dab tsi?
Video: Lus Qhuab Qhia | "Lub Tswv Yim ntawm qhov Muaj Peb Tug Puas Muaj Qab Hau?" 2024, Kaum ib hlis
Anonim

Muaj ob hom modifiers hauv Java : nkag mus modifiers thiab tsis- nkag mus modifiers . Cov nkag mus modifiers hauv Java qhia txog kev nkag mus tau los yog thaj tsam ntawm thaj chaw, txoj kev, tus tsim, lossis chav kawm. Peb tuaj yeem hloov tau nkag mus theem ntawm teb, constructors, txoj kev, thiab chav kawm ntawv los ntawm kev siv lub access modifier ntawm nws.

Tsuas yog li ntawd, yog dab tsi yog siv cov kev hloov kho hauv Java?

Java access modifiers yog siv muab nkag mus tswj hauv java ua . Java muab nkag mus tswj los ntawm peb lo lus tseem ceeb - ntiag tug, tiv thaiv thiab pej xeem. Peb tsis tas yuav siv cov no nkag mus modifiers ib txwm, yog li peb muaj lwm lub npe hu ua "default nkag mus ", "package-private" lossis "no hloov kho “.

Tsis tas li ntawd, dab tsi yog qhov hloov pauv nkag mus thiab vim li cas nws tseem ceeb? Access modifiers yog siv rau encapsulation: lawv tso cai rau koj los npaj koj cov cai nyob rau hauv tej pob khoom thiab cov chav kawm, thiab tsuas muaj ib tug "official" pej xeem interface pom rau sab nraud, thaum nkaum cov ntsiab lus ntawm kev siv (uas koj xav ua, ces koj yuav tau tom qab hloov nws. tsis qhia leej twg).

Tsis tas li ntawd, vim li cas peb thiaj siv nkag mus rau hauv java?

- Java Access Specifiers (tseem hu ua Visibility Specifiers ) tswj nkag mus rau cov chav kawm, teb thiab cov txheej txheem hauv Java . Cov no Specifiers txiav txim seb ib daim teb lossis txoj hauv kev hauv chav kawm, tuaj yeem ua tau siv los yog invoked los ntawm lwm txoj kev nyob rau hauv lwm chav kawm ntawv los yog sub-class. Access Specifiers tuaj yeem yog siv txwv nkag mus.

Dab tsi yog hom kev hloov pauv nkag?

Access Modifiers Hom. C# muab plaub hom kev hloov pauv nkag: tus kheej , pej xeem, tiv thaiv, sab hauv, thiab ob qho tib si: tiv thaiv-hauv thiab tus kheej - tiv thaiv.

Pom zoo: