Peb puas tuaj yeem tshaj tawm txoj haujlwm tseem ceeb hauv Java?
Peb puas tuaj yeem tshaj tawm txoj haujlwm tseem ceeb hauv Java?

Video: Peb puas tuaj yeem tshaj tawm txoj haujlwm tseem ceeb hauv Java?

Video: Peb puas tuaj yeem tshaj tawm txoj haujlwm tseem ceeb hauv Java?
Video: MUS HAUV NROOG KOJ PUAS TSEEM NTSEEG || TUB ME MUAS NKAUJ NTSEEG TAWM TSHIAB 2022,2023 2024, Kaum ib hlis
Anonim

Yog lawm, peb tuaj yeem tshaj tawm tus txoj kev loj raws li private hauv Java . Nws compiles ua tiav yam tsis muaj qhov yuam kev tab sis ntawm lub sijhawm ua haujlwm, nws hais tias qhov txoj kev loj tsis yog pej xeem.

Ib yam li ntawd, tib neeg nug, peb puas tuaj yeem tshaj tawm txoj hauv kev tseem ceeb hauv Java?

Teb: Yog, peb tuaj yeem tshaj tawm txoj kev tseem ceeb asprivate . Nws compiles yam tsis muaj qhov yuam kev, tab sis hauv runtime, nws hais txoj kev loj tsis yog pej xeem.

Qhov thib ob, vim li cas peb thiaj li siv tus kheej hauv Java? Hauv Summary tus kheej lo lus tseem ceeb hauv java ua tso cai rau kev txwv tsis pub nkag mus rau qhov sib txawv thiab cov txheej txheem thiab muab daim ntawv muaj zog tshaj plaws ntawm Encapsulation. tus kheej cov tswv cuab tsis siv tau sab nraum chav kawm thiab tus kheej txoj kev yuav tsis beoverridden.

Ib yam li ntawd ib tug yuav nug, vim li cas txoj kev tseem ceeb tsis yog tus kheej hauv Java?

Hauv Java , thaum twg peb tshaj tawm cov tswv cuab (xws li hloov pauv lossis txoj kev ) ntawm class as tus kheej , cov tswv cuab tuaj yeem nkag tau los ntawm hauv chav kawm ntawd nkaus xwb. Lawv yuav tsis yog pom rau txhua chav kawm sab nraum chav kawm no.

Peb puas tuaj yeem tshaj tawm cov chav kawm sab hauv ua tus kheej?

Tsis zoo li ib chav kawm , ib chav kawm sab hauv tuaj yeem ua tus kheej thiab ib zaug koj tshaj tawm ib inner classprivate , nws tsis tuaj yeem nkag los ntawm ib qho khoom sab nraud chav kawm . Hauv qab no yog qhov program los tsim ib qho chav kawm sab hauv thiab nkag mus rau nws.

Pom zoo: