This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// Make a Car called Chuck going 10 MPH



Download 21,46 Mb.
Pdf ko'rish
bet316/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   312   313   314   315   316   317   318   319   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Make a Car called Chuck going 10 MPH.

Car chuck = new Car();

chuck.PrintState();

// Make a Car called Mary going 0 MPH.

Car mary = new Car("Mary");

mary.PrintState();

// Make a Car called Daisy going 75 MPH.

Car daisy = new Car("Daisy", 75);

daisy.PrintState();

}

The Default Constructor Revisited

As you have just learned, all classes are endowed with a free default constructor. Thus, if you insert a

new class into your current project named Motorcycle, defined like so:

class Motorcycle

{

public void PopAWheely()



{

Console.WriteLine("Yeeeeeee Haaaaaeewww!");

}

}

you are able to create an instance of the Motorcycle type via the default constructor out of the box:



static void Main(string[] args)

{

Motorcycle mc = new Motorcycle();



mc.PopAWheely();

}

However, as soon as you define a custom constructor, the default constructor is silently removed



from the class and is no longer available! Think of it this way: if you do not define a custom con-

structor, the C# compiler grants you a default in order to allow the object user to allocate an

instance of your type with field data set to the correct default values. However, when you define

a unique constructor, the compiler assumes you have taken matters into your own hands.

C H A P T E R   5  


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   312   313   314   315   316   317   318   319   ...   1830




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