Video: Yuav ua li cas ib tug variable ua ib chav kawm sib txawv?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
Txhua piv txwv ntawm chav kawm shares ib chav kawm sib txawv , qho yog nyob rau hauv ib qho chaw ruaj khov hauv nco. Tej yam khoom ua tau hloov tus nqi ntawm a chav kawm sib txawv , mas class variables tau kuj yuav manipulated yam tsis muaj tsim ib piv txwv ntawm chav kawm . A chav kawm sib txawv (tau tshaj tawm zoo li qub ) yog ib qho chaw nyob rau txhua qhov xwm txheej.
Ib yam li ntawd, koj tuaj yeem nug, chav kawm puas tuaj yeem yog hom sib txawv?
Nyob rau hauv object-oriented programming nrog chav kawm , a chav kawm sib txawv yog ib qho sib txawv tshaj tawm nrog tus hloov kho zoo li qub uas muaj ib daim ntawv luam tawm, txawm tias muaj pes tsawg zaus ntawm chav kawm muaj. Nws yog ib qho tshwj xeeb hom ntawm chav kawm attribute (los yog chav kawm vaj tse, teb, los yog cov ntaub ntawv tus tswv cuab).
Qhov thib ob, txoj kev sib txawv yog dab tsi? Ib yam li x yog txhais hauv lub ntsiab txoj kev , thiab tsuas yog siv tau rau hauv. Scope ntawm x yog lub ntsiab txoj kev . Yog li x thiab y nyob ntawm ib leeg ntawm ib leeg, nyob rau hauv lawv qhov kev sib raug zoo txoj kev . 12. Lawv hu ua method variables.
Tsuas yog li ntawd, koj yuav ua li cas tshaj tawm cov chav kawm sib txawv?
Java muab peb hom sib txawv . Chav kawm variable − Chav kawm variable kuj hu ua static sib txawv yog tshaj tawm nrog rau lo lus tseem ceeb static hauv a chav kawm , tab sis sab nraum ib txoj kev, constructor lossis block. Yuav tsuas muaj ib daim qauv ntawm txhua tus chav kawm sib txawv rau chav kawm , tsis hais ntau npaum li cas cov khoom raug tsim los ntawm nws.
Dab tsi yog qhov txawv ntawm qhov sib txawv ntawm chav kawm thiab qhov sib txawv piv txwv?
Static( Chav kawm ) sib txawv thiab piv txwv variables ob leeg yog tswv cuab sib txawv vim lawv ob leeg koom nrog ib qho tshwj xeeb chav kawm , mas cov qhov sib txawv ntawm lawv yog Chav kawm variable tsuas muaj ib daim ntawv uas tau muab los ntawm txhua tus qhov txawv cov khoom ntawm a chav kawm , whereas txhua yam khoom muaj nws tus kheej daim ntawv luam ntawm ib tug piv txwv
Pom zoo:
Kev sib cav sib ceg sib txawv li cas ntawm kev sib cav tsis zoo?
Txhua qhov kev sib cav tsis zoo siv txoj cai invalid inference. Yog tias qhov kev sib cav tsis zoo koj paub tias nws tsis siv. Kev siv tau txhais tau tias tsis muaj kev txhais lus qhov twg qhov chaw muaj tseeb thiab qhov kev txiav txim siab tuaj yeem tsis tseeb ib txhij. Yog tias qhov kev sib cav ua txhaum koj tuaj yeem tsis quav ntsej nws thiab sim nkag siab lub ntsiab lus tseem
Dab tsi yog ob chav kawm tshwj xeeb hauv hierarchy ntawm Java zam chav kawm?
Chav Kawm Exception muaj ob lub ntsiab subclasses: IOException class thiab RuntimeException Class. Hauv qab no yog cov npe ntawm feem ntau kuaj xyuas thiab tsis tau txheeb xyuas Java's Built-in Exceptions
Peb puas tuaj yeem muaj ntau chav kawm pej xeem hauv chav kawm hauv Java?
Yog, nws ua tau. Txawm li cas los xij, muaj peev xwm tsuas yog ib pawg pej xeem ib. java cov ntaub ntawv, raws li publicclasses yuav tsum muaj tib lub npe raws li cov ntaub ntawv qhov chaw. OneJava cov ntaub ntawv tuaj yeem muaj ntau chav kawm nrog kev txwv uas tsuas yog ib qho ntawm lawv tuaj yeem ua pej xeem
Chav kawm piav qhia txog tus qauv ntawm chav kawm yog dab tsi?
Nyob rau hauv object-oriented programming, ib chav kawm yog ib tug template txhais ntawm txoj kev s thiab txawv txawv s nyob rau hauv ib tug tej yam khoom. Yog li, ib yam khoom yog ib qho piv txwv tshwj xeeb ntawm chav kawm; nws muaj cov txiaj ntsig tiag tiag tsis yog hloov pauv. Cov qauv ntawm ib chav kawm thiab nws cov subclasses yog hu ua chav kawm hierarchy
Dab tsi yog qhov txawv ntawm qhov piv txwv hauv zos thiab chav kawm sib txawv?
Cov kev hloov hauv zos tsis pom sab nraum txoj kev. Cov piv txwv sib txawv tau tshaj tawm hauv chav kawm, tab sis sab nraum ib txoj hauv kev. Lawv kuj raug hu ua cov tswv cuab lossis cov kev hloov pauv. Class/static variables tau tshaj tawm nrog lo lus tseem ceeb zoo li qub hauv chav kawm, tab sis sab nraum ib txoj kev