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



Download 3,91 Mb.
Pdf ko'rish
bet66/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   62   63   64   65   66   67   68   69   70
Bog'liq
Java for Fucking Idiots

class
Meme
extends
Object {
}
But don’t do that. Java does that for us.
Also, yes, Java says extends rather than “inherits from.” Don’t try to extend
your parents, whatever that means.
Coitus
Let’s create some actual inheritance of our own:
class
Monster {
int
health
=
10
;
int
damage
=
2
;


void
attack(Monster monsterToAttack) {
monsterToAttack.
health
-=
damage
;
}
}
Here, we have a simple Monster class. Any Monster created from this class
starts off with 10 
health
, 2 
damage
, and the ability to attack another
monster.
But we’re striving to make the greatest monster-themed video game of the
21
st
century. One to rival the likes of Pokemon or The Witcher!! Not all of
them will be the same!
Let’s make this more interesting; specialized, child Monster classes!
First, a 
Goblin
. It will have lower health, and lower damage, because
fucking Goblins are always the weakest of the bunch.
class
Goblin
extends
Monster {
Goblin() {
health
=
5
;
damage
=
1
;
}
}
What we did here was create a new class called 
Goblin
that inherits from
Monster
. It has its own constructor that specifies its unique values; 5 
health
, and 1 
damage
.
By the magic of inheritance, it also can 
attack
, because it is a Monster. And
the Monster class is the one who defined that method.
Yep, that means you could do this: 
Goblin warts =
new
Goblin();
warts.attack(someOtherMonster);
Just like that! The Goblin can fight! Woo!!!


Let’s make another one! This one will be stronger; a big tough golem.

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   62   63   64   65   66   67   68   69   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