— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet241/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   237   238   239   240   241   242   243   244   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

public class Mushroom {
public Mushroom
(int size)
 { }
public Mushroom
( )
 { }
public Mushroom
(boolean isMagic)
 { }
public Mushroom
(boolean isMagic, int size)
 { }
public Mushroom
(int size, boolean isMagic)
 { }
}
when you know the size, but you 
don’t know if it’s magic 
when you don’t know anything
when you know if it’s magic or not, 
but don’t know the size
when you know 
whether or not it’s 
magic, AND you know 
the size as well
Overloaded constructors means you have 
more than one constructor in your class. 
To compile, each constructor must have a 
different argument list!
The class below is legal because all four constructors have 
different argument lists. If you had two constructors that took 
only an int, for example, the class wouldn’t compile. What you 
name the parameter variable doesn’t count. It’s the variable 
type (int, Dog, etc.) and order that matters. You can have two 
constructors that have identical types, as long as the order is 
different
. A constructor that takes a String followed by an int, is 
not the same as one that takes an int followed by a String.
these two have the 
same args, but in 
different order, so 
it’s OK


248
 
chapter 9
Q:
Earlier you said that it’s good to have a no-argu-
ment constructor so that if people call the no-arg con-
structor, we can supply default values for the “missing” 
arguments. But aren’t there times when it’s impossible to 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   237   238   239   240   241   242   243   244   ...   555




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