C# 0 The Complete Reference


Triangle( )  calls  base



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

Triangle( )

 calls 


base

 with the parameters 



w

 and 


h

. This causes the 



TwoDShape( )

 constructor to be called, which initializes 



Width

 and 


Height

 using these 

values.

Triangle

 no longer initializes these values itself. It need only initialize the value 

unique to it: 

Style

. This leaves 



TwoDShape

 free to construct its subobject in any manner 

that it chooses. Furthermore, 

TwoDShape

 can add functionality about which existing 

derived classes have no knowledge, thus preventing existing code from breaking.

Any form of constructor defined by the base class can be called by 



base

. The constructor 

executed will be the one that matches the arguments. For example, here are expanded 

versions of both 



TwoDShape

 and 


Triangle

 that include default constructors and constructors 

that take one argument.

// Add more constructors to TwoDShape.

using System;

class TwoDShape {

  double pri_width;

  double pri_height;

  // Default constructor.

  public TwoDShape() {

    Width = Height = 0.0;

  }


  // Constructor for TwoDShape.

  public TwoDShape(double w, double h) {

    Width = w;

    Height = h;

  }

  // Construct object with equal width and height.



  public TwoDShape(double x) {

    Width = Height = x;

  }

  // Properties for Width and Height.



  public double Width {

     get { return pri_width; }

     set { pri_width = value < 0 ? -value : value; }

  }


www.freepdf-books.com


Download 4,07 Mb.

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