Video: Dab tsi yog cov tswv cuab ntawm chav kawm Java?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2024-01-18 08:24
primitive data type, objects, method like getter and setters, constructors in chav kawm yog lub npe hu ua cov tub kawm . Cov tswv cuab txhais tau hais tias leej twg yog tus chav kawm.
Muaj tsib tug tswv cuab hauv ib chav kawm.
- Tus tswv cuab Variables (States)
- Methods (Cwj pwm)
- Tus tsim.
- Blocks (Instance / Static Blocks)
- Sab hauv Cov chav kawm .
Ib yam li ntawd, ib tug yuav nug, cov tswv cuab ntawm chav kawm yog dab tsi?
Cov tub kawm , hauv C#, yog cov cov tswv cuab ntawm a chav kawm uas sawv cev rau cov ntaub ntawv thiab tus cwj pwm ntawm a chav kawm . Cov tub kawm yog cov tswv cuab tshaj tawm nyob rau hauv lub chav kawm thiab tag nrho cov (tsis suav cov neeg tsim kho thiab cov destructors) tshaj tawm nyob rau hauv tag nrho chav kawm nyob rau hauv nws qhov qub txeeg qub teg hierarchy.
Tom qab ntawd, lo lus nug yog, dab tsi yog chav kawm sib txawv hauv Java? 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. Nco ntsoov tias hauv Java , cov ntsiab lus "field" thiab " sib txawv " siv interchangeably rau cov tswv cuab sib txawv.
Kuj kom paub yog, dab tsi yog cov tswv cuab hauv Java?
Cov ntaub ntawv tus tswv cuab tsis muaj dab tsi tab sis qhov sib txawv ntawm ib yam khoom. Piv txwv li, tus neeg siv khoom tuaj yeem muaj cov tswv cuab cov ntaub ntawv rau npe thiab hnub nyoog. Txhua yam ntawm cov neeg siv khoom khaws cov khoom muaj nqis rau cov npe thiab hnub nyoog. Hauv Java Data cov tswv cuab tsis muaj dab tsi tab sis a sib txawv , piv sib txawv.
Txoj kev kawm yog dab tsi?
A chav kawm txoj kev yog a txoj kev uas yog khi rau lub chav kawm thiab tsis yog khoom ntawm lub chav kawm . Lawv muaj kev nkag tau mus rau lub xeev ntawm lub chav kawm raws li nws siv a chav kawm parameter uas taw tes rau lub chav kawm thiab tsis yog qhov khoom piv txwv. Piv txwv li nws tuaj yeem hloov kho a chav kawm variable uas yuav siv tau rau txhua qhov piv txwv.
Pom zoo:
Dab tsi yog qhov txawv ntawm chav kawm sab hauv thiab cov chav nested?
Cov chav kawm uas tau tshaj tawm yam tsis siv qhov zoo li qub yog hu ua chav kawm sab hauv lossis chav kawm tsis zoo li qub. Cov chav kawm Staticnested yog chav kawm zoo li lwm cov tswv cuab zoo li qub ntawm cov chav kawm sab nrauv. Txawm li cas los xij, cov chav kawm sab hauv yog khi toinstance thiab nws tuaj yeem nkag mus rau cov tswv cuab ntawm pawg enclosingclass
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
Ob hom tswv cuab ntawm ib chav kawm yog dab tsi?
Cov chav kawm muaj peev xwm muaj cov hauv qab no ua ib tug tswv cuab ntawm chav kawm. Tab sis, feem ntau muaj ob hom ntawm cov tub kawm uas nquag siv yog: Cov tswv cuab cov ntaub ntawv (Variables) Function Members (Txoj Kev)
Ib tug tswv cuab tiv thaiv yuav ua li cas yog tias cov chav kawm tau txais qub txeeg qub teg hauv pej xeem hom?
1) nyob rau hauv kev tiv thaiv qub txeeg qub teg, cov pej xeem thiab cov tswv cuab tiv thaiv los ua cov tswv cuab tiv thaiv nyob rau hauv chav kawm derived. Nyob rau hauv tus kheej qub txeeg qub teg, txhua yam yog ntiag tug. Vim tias lawv yog ib feem ntawm cov chav kawm hauv paus, thiab koj xav tau cov chav kawm hauv paus uas yog ib feem ntawm koj cov chav kawm derived
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