C# 0 The Complete Reference


abstract  and  sealed



Download 4,07 Mb.
Pdf ko'rish
bet398/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   394   395   396   397   398   399   400   401   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

abstract

 and 


sealed

 because an abstract 

class is incomplete by itself and relies upon its derived classes to provide complete 

implementations.

Here is an example of a 

sealed

 class:


sealed class A {

  // ...


}

// The following class is illegal.

class B : A { // ERROR! Can't derive from class A

  // ...


}

As the comments imply, it is illegal for 



B

 to inherit 



A

 because 



A

 is declared as 



sealed

.

One other point: 



sealed

 can also be used on virtual methods to prevent further 

overrrides. For example, assume a base class called 

B

 and a derived class called 



D

. A 


method declared 

virtual

 in 


B

 can be declared 



sealed

 by 


D

. This would prevent any class 

that inherits 

D

 from overriding the method. This situation is illustrated by the following:

class B {

  public virtual void MyMethod() { /* ... */ }

}

class D : B {



  // This seals MyMethod() and prevents further overrides.

  sealed public override void MyMethod() { /* ... */ }

}

class X : D {



  // Error! MyMethod() is sealed!

  public override void MyMethod() { /* ... */ }

}

Because



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   394   395   396   397   398   399   400   401   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish