Cov chav kawm abstract puas muaj tus tsim?
Cov chav kawm abstract puas muaj tus tsim?

Video: Cov chav kawm abstract puas muaj tus tsim?

Video: Cov chav kawm abstract puas muaj tus tsim?
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Hlis ntuj nqeg
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.

Tsuas yog li ntawd, 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.

Kuj Paub, cov chav kawm paub daws teeb meem puas muaj tus tsim C#? Teb: Yog, ib chav kawm abstract tuaj yeem muaj a tus tsim , txawm tias chav kawm abstract tsis tau instantiated. Ib abstract class constructor c# code piv yuav piav qhia. Piv txwv li nyob rau hauv qhov kev pab cuam, yog tias peb tsim khoom ntawm derived chav kawm ces abstract puag class constructor yuav kuj hu ua.

Tom qab ntawd, ib tus tuaj yeem nug, cov chav kawm paub daws teeb meem puas tuaj yeem muaj tus tsim qauv tsim hauv Java?

Yog, ib chav kawm abstract tuaj yeem muaj a parameterized tsim . Qhov no yuav tom qab ntawd siv los ntawm subclasses uas txuas ntxiv rau chav kawm abstract.

Koj hu ua abstract class constructor li cas?

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.

Pom zoo: