C# 0 The Complete Reference


Triangle ’s constructor initializes the members of  TwoDShape



Download 4,07 Mb.
Pdf ko'rish
bet368/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   364   365   366   367   368   369   370   371   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Triangle

’s constructor initializes the members of 



TwoDShape

 that it inherits along 

with its own 

Style

 field.


When both the base class and the derived class define constructors, the process is a 

bit more complicated because both the base class and derived class constructors must be 

executed. In this case, you must use another of C#’s keywords, 

base

, which has two uses. 

The first use is to call a base class constructor. The second is to access a member of the base 

class that has been hidden by a member of a derived class. Here, we will look at its first use.



Calling Base Class Constructors

A derived class can call a constructor defined in its base class by using an expanded form 

of the derived class’ constructor declaration and the 

base

 keyword. The general form of this 

expanded declaration is shown here:

derived-constructor

(

parameter-list

) : base(

arg-list

) {


   // body of constructor

}

Here, 



arg-list

 specifies any arguments needed by the constructor in the base class. Notice the 

placement of the colon.

To see how 



base

 is used, consider the version of 



TwoDShape

 in the following program. 

It defines a constructor that initializes the 

Width

 and 


Height

 properties. This constructor is 

then called by the 

Triangle

 constructor.

// Add constructor to TwoDShape.

using System;

// A class for two-dimensional objects.

class TwoDShape {

  double pri_width;

  double pri_height;

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   364   365   366   367   368   369   370   371   ...   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