A txoj kev zoo li qub yog nyob rau hauv chav kawm thiab txoj kev tsis zoo li qub yog ib yam khoom ntawm chav kawm. Cov txheej txheem zoo li qub tuaj yeem nkag ncaj qha los ntawm chav kawm, thaum txoj kev tsis zoo li qub (lossis cov qauv piv txwv raws li kuv nyiam hu rau lawv) yuav tsum tau nkag los ntawm ib qho piv txwv.
Thaum twg yuav tsum muaj txoj hauv kev zoo li qub vs tsis zoo li qub?
A static method belongs rau cov chav kawm nws tus kheej thiab ib txoj kev tsis zoo li qub (aka piv txwv) belongs rau txhua yam khoom uas yog tsim los ntawm chav kawm ntawd. Yog tias koj txoj kev ua ib yam dab tsi uas tsis nyob ntawm tus yam ntxwv ntawm nws chav kawm, ua kom zoo li qub (nws yuav ua rau qhov kev zov me nyuam hneev taw me dua).
Thaum twg koj yuav siv txoj kev tsis zoo li qub?
Ib txoj kev tsis zoo li qub hauv Java tuaj yeem nkag mus tau zoo li qub thiab hloov pauv raws li hauv qab no:
- Ib txoj kev tsis zoo li qub tuaj yeem nkag mus rau txhua txoj kev zoo li qub yam tsis tau tsim ib qho piv txwv ntawm chav kawm.
- Ib txoj kev tsis zoo li qub tuaj yeem nkag mus rau txhua qhov sib txawv zoo li qub yam tsis tau tsim ib qho piv txwv ntawm chav kawm vim tias qhov sib txawv zoo li qub yog nyob rau hauv chav kawm.
Thaum twg koj yuav tsum siv cov haujlwm zoo li qub?
Thaum koj xav kom muaj qhov sib txawv uas ib txwm muaj txiaj ntsig zoo ib yam rau txhua yam khoom ntawm chav kawm, mus ib txhis, ua kom zoo li qub. Yog tias koj muaj ib txoj hauv kev uas tsis siv cov piv txwv piv txwv lossis cov qauv piv txwv, koj yuav tsum ua kom zoo li qub.
Dab tsi yog qhov txawv ntawm qhov zoo li qub thiab tsis zoo li qub?
Static variables or fields belongs to class, and not to any object of class. Ib qho kev hloov pauv zoo li qub yog pib thaum cov chav kawm thauj khoom ntawm lub sijhawm ua haujlwm. Non-static fields yog thaj chaw piv txwv ntawm ib qho khoom. Lawv tsuas tuaj yeem nkag mus lossis hu los ntawm cov khoom siv.