Cov txheej txheem:

Koj sau cam hauv Java li cas?
Koj sau cam hauv Java li cas?

Video: Koj sau cam hauv Java li cas?

Video: Koj sau cam hauv Java li cas?
Video: nyiag nkag koj tus hluas nkauj tus messenger ua koj twb g paub password 2024, Kaum ib hlis
Anonim

Hloov pauv

  1. Hom Casting hauv Java . Hom casting yog siv rau hloov ib yam khoom los yog hloov pauv ntawm ib qho hom rau hauv lwm tus.
  2. Syntax. dataType variableName = (dataType) variableToConvert;
  3. Sau ntawv. Muaj ob casting cov lus qhia: nqaim (loj mus rau me me hom ) thiab widening (me me mus rau loj hom ).
  4. Piv txwv.

Ib yam li ntawd, nws yog nug, dab tsi yog casting hauv Java nrog piv txwv?

Hom casting hauv Java yog to pov tseg ib hom, ib chav kawm lossis interface, rau lwm hom piv txwv li lwm chav kawm lossis interface. Hom casting kuj los nrog kev pheej hmoo ntawm ClassCastException hauv Java , uas yog feem ntau nrog ib txoj kev uas lees txais hom hom thiab tom qab hom pov tseg rau hauv hom tshwj xeeb.

Ib tug kuj yuav nug, dab tsi yog casting hauv Java? Casting txhais tau tias xaiv ib qho Yam khoom ntawm ib hom tshwj xeeb thiab ua rau lwm tus Yam khoom hom. Cov txheej txheem no hu ua casting qhov sib txawv. Qhov tseeb, cov ntaub ntawv no tsis yog tshwj xeeb rau Java, raws li ntau lwm yam lus programming pab casting ntawm lawv hom sib txawv.

Tsis tas li ntawd, dab tsi yog hom casting nrog piv txwv?

Typecasting . Typecasting , los yog hom conversion, yog ib txoj kev hloov ib qho chaw los ntawm ib cov ntaub ntawv hom rau lwm tus. Ib piv txwv ntawm ntaus ntawv yog converting ib tug integer rau ib txoj hlua. Qhov no yuav ua tau kom sib piv ob tus lej, thaum ib tus lej tau txais kev cawmdim raws li txoj hlua thiab lwm qhov yog tus lej.

Dab tsi yog hom ntaub ntawv hauv Java?

Hom ntaub ntawv qhia qhov loj thiab hom ntawm qhov tseem ceeb uas tuaj yeem khaws cia rau hauv tus cim. Cov Java lus yog nplua nuj nyob rau hauv nws hom ntaub ntawv . Cov ntaub ntawv hom hauv Java raug cais ua ob hom : Primitive-uas suav nrog Integer, Cim, Boolean, thiab Floating Point. Non-primitive-uas suav nrog Chav Kawm, Interfaces, thiab Arrays.

Pom zoo: