C# 0 The Complete Reference


TwoDShape  used in the preceding example.  The definition of  Area( )



Download 4,07 Mb.
Pdf ko'rish
bet393/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   389   390   391   392   393   394   395   396   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

TwoDShape

 used in the preceding example. 

The definition of 

Area( )

 is simply a placeholder. It will not compute and display the area of 

any type of object.

You will see as you create your own class libraries that it is not uncommon for a method 

to have no meaningful definition in the context of its base class. You can handle this situation 

two ways. One way, as shown in the previous example, is to simply have it report a warning 

message. Although this approach can be useful in certain situations—such as debugging—it 

is not usually appropriate. You may have methods that must be overridden by the derived 

class in order for the derived class to have any meaning. Consider the class 

Triangle

. It is 


incomplete if 

Area( )

 is not defined. In such a case, you want some way to ensure that a 

derived class does, indeed, override all necessary methods. C#’s solution to this problem is 

the


abstract method.

An abstract method is created by specifying the



abstract

 type modifier. An abstract 

method contains no body and is, therefore, not implemented by the base class. Thus, a 

derived class must override it—it cannot simply use the version defined in the base class. 

As you can probably guess, an abstract method is automatically virtual, and there is no 

need to use the 



virtual

 modifier. In fact, it is an error to use 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   389   390   391   392   393   394   395   396   ...   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