Java for Fucking Idiots: Learn the Basics of Java Programming Without any experience!



Download 3,91 Mb.
Pdf ko'rish
bet42/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   38   39   40   41   42   43   44   45   ...   70
Bog'liq
Java for Fucking Idiots

new
House();
System.
out
.println(stevesHouse.
color
);
stevesHouse.
color
=
"Blue"
;
System.
out
.println(stevesHouse.
color
);
> Gray
> Blue
That’s fine…
Or, you could get it the color you want right from the start.
Check it out!
class
House {
String
color
;
House(String customColor) {
color
= customColor;
}
}
The parentheses are no longer empty! Can you guess what’s happening
here?


Even if you figured it out, the vocabulary is always just memorization. My
least favorite part of any test. Or life.
customColor
is called a parameter .
By putting this parameter in our constructor, if someone wants to build a
house, they must now provide a color!
House stevesHouse = 
new
House();
That doesn’t work anymore, dumbass!!! Sorry that was a bit harsh.
Especially since you didn’t write it, I did.
But since you made a constructor that requires the customColor parameter,
Java will murder your firstborn child if you try to build a House without
specifying a color.
How ‘bout this?
House stevesHouse =
new
House(
"Blue"
);
System.
out
.println(stevesHouse.
color
);
Yep, that works! We build the house, and it’s blue. “Blue” is printed to the
console.
Brain teaser!
What do you think happens here?
class
House {
String
color
=
"Gray"
;
House() {
color
=
"White"
;
}
}
What color is printed if I do
House coloredHouse =

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   38   39   40   41   42   43   44   45   ...   70




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