Dab tsi yog qhov txawv ntawm chav kawm sab hauv thiab cov chav nested?
Dab tsi yog qhov txawv ntawm chav kawm sab hauv thiab cov chav nested?

Video: Dab tsi yog qhov txawv ntawm chav kawm sab hauv thiab cov chav nested?

Video: Dab tsi yog qhov txawv ntawm chav kawm sab hauv thiab cov chav nested?
Video: 5 Yam: Txhob pub muaj nyob hauv Tsev (Tsis Zoo) 2024, Hlis ntuj nqeg
Anonim

Chav kawm uas tau tshaj tawm yam tsis tau siv static iscalled chav kawm sab hauv los yog tsis zoo li qub chav kawm nested . Static chav kawm nested yog chav kawm qib zoo li lwm cov tswv cuab zoo li qub ntawm sab nrauv chav kawm . Txawm li cas los xij, chav kawm sab hauv yog tied toinstance thiab nws tuaj yeem nkag mus rau cov tswv cuab ntawm cov enclosing chav kawm.

Ntawm no, qhov txawv ntawm chav kawm sab hauv thiab chav kawm sub yog dab tsi?

cov chav kawm sab hauv yog hauv tib cov ntaub ntawv, whereas subclasses tuaj yeem nyob hauv lwm cov ntaub ntawv, tej zaum hauv lwm pob. Koj tsis tuaj yeem tau txais ib qho piv txwv ntawm ib qho chav kawm sab hauv tsis muaj ib qho piv txwv ntawm cov chav kawm uas muaj nws. cov chav kawm sab hauv muaj cov kev uas lawv xav tau, whereas subclasses muaj cov txheej txheem ntawm lawv niam lawv txiv chav kawm.

Ib yam li ntawd, cov chav kawm sab hauv yog dab tsi thiab dab tsi yog hom? Muaj plaub hom ntawm cov chav kawm sab hauv : tus tswv cuab, tus tswv cuab zoo li qub, hauv zos, thiab tsis qhia npe. Ib tug tswv cuab chav kawm yog txhais nyob rau theem sab saum toj ntawm lub chav kawm.

Tsis tas li lo lus nug yog, dab tsi yog qhov ntawm cov chav kawm nested hauv lwm chav kawm?

A chav kawm tuaj yeem tshaj tawm hauv tus thaj tsam ntawm lwm chav kawm . Xws li ib chav kawm hu ua " chav kawm nested ." Nested chav kawm raug suav hais tias yog hauv tus thaj tsam ntawm qhov kaw chav kawm andare muaj rau siv hauv uas thaj tsam.

static nested class yog dab tsi?

A chav kawm zoo li qub i.e. tsim nyob rau hauv a chav kawm hu ua static nested chav kawm hauv java ua . Nws tuaj yeem nkag los ntawm sab nraud chav kawm npe. Nws tuaj yeem nkag tau zoo li qub cov ntaub ntawv cov tswv cuab ntawm sab nraud chav kawm suav nrog tus kheej. Cov chav kawm Staticnesed tsis tuaj yeem nkag mus tsis tau zoo li qub (xws li) datamember lossis method.

Pom zoo: