Java abstract class puas muaj tus tsim?
Java abstract class puas muaj tus tsim?

Video: Java abstract class puas muaj tus tsim?

Video: Java abstract class puas muaj tus tsim?
Video: Как развиваться, если ты Senior или Lead? Интервью с Павел Вейник: так растут разработчики. 2024, Kaum ib hlis
Anonim

Yog, ib chav kawm abstract tuaj yeem muaj a tus tsim hauv Java . Koj ua tau los yog qhia meej meej a tus tsim rau chav kawm abstract los yog koj tsis ua, lub compiler yuav ntxiv default tus tsim ntawm tsis muaj kev sib cav hauv chav kawm abstract . Qhov no muaj tseeb rau txhua tus chav kawm thiab nws kuj siv tau rau ib qho chav kawm abstract.

Yog li ntawd, tus tsim qauv puas tuaj yeem paub daws teeb meem hauv Java?

Koj ua tau 'tsis muaj abstract constructor , as abstract txhais tau tias koj yuav tsum tau muab qhov kev siv rau qhov ntawd ntawm qee lub sijhawm hauv koj cov subclass. Tab sis koj tsis tuaj yeem override tus tsim . Nyob ntawd yuav yuav tsis muaj teeb meem nyob rau hauv muaj ib tug abstract constructor : Koj yuav ib txwm hu rau tus tsim ntawm chav kawm me nyuam thiab tsis yog chav kawm hauv paus.

Ib yam li ntawd, koj hu li cas rau cov chav kawm paub daws teeb meem? Koj tuaj yeem txhais a tus tsim hauv ib chav kawm abstract , tab sis koj tsim tsis tau qhov khoom ntawd. Txawm li cas los xij, kev sib koom ua ke sub- chav kawm tuaj yeem (thiab yuav tsum) hu ib cov tus tsim txhais nyob rau hauv lub abstract niam txiv chav kawm . Koj ua tsis tau hu ib abstract class constructor nrog a chav kawm piv txwv creation expression, i.e.

Ib yam li ntawd, tib neeg nug, vim li cas chav kawm paub daws teeb meem muaj tus tsim?

A tus tsim hauv Java tsis tau "tsim" cov khoom, nws yog siv los pib ua teb. Xav tias koj abstract chav kawm muaj teb x thiab y, thiab koj ib txwm xav kom lawv pib ua ib txoj hauv kev, txawm li cas los xij qhov tseeb subclass yog qhov kawg tsim.

Cov chav kawm abstract puas muaj cov khoom hauv Java?

Vim nws yog abstract thiab ib khoom yog pob zeb. Tsis yog, cov neeg tsim qauv tsis tau muab txoj hauv kev. Vim ib chav kawm abstract yog ib qho tsis tiav chav kawm (tsis tiav nyob rau hauv qhov kev txiav txim nws muaj abstract txoj kev tsis muaj lub cev thiab cov zis) peb tsim tsis tau ib qho piv txwv lossis khoom ; tib yam li koj hais rau lub interface.

Pom zoo: