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



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

private and public are access modifiers. There’s two other ones.
If you don’t specify one , your class, method, or property is considered
package private . It’s basically the default. Other classes in the same
package can see you.


protected is a specialized version of that. Except a child class can see that
method or property as well.
Inheritance
Which “inheritance” would you rather have?
A. Several million dollars in savings from your beloved parents who
were responsible with their money and left it to their children.
B. Some of their traits, like hair color, height, personality…
hyperactive depression…ability to ride a unicycle, wiggle their
ears….
Option B , right? Obviously! Who needs money, not me right? Ha. Ha haha.
Please rate the book 5 stars and like, follow, and subscribe for more content.
What is inheritance?
Defining a class that is a more specific version of another class. Defining a
class that is the “child” of a “parent” class. A way to reuse code without
copy-pasting it. Another way to model our code in an easy-to-understand
way for humans.
In Java, a class does not find another class, hook up, and just have a child.
Unfortunately enough for them…
The child is a specialized version of the parent. The child inherits the
properties and methods of the parent. The child is a “subclass” of the
parent.
When you’re thinking through how you want to write a program, whether
that be a website, app, database utility, video game, or college assignment,
you often will find many parts of the program will share similar traits.
Maybe your app will have a bunch of different screens that share the same
color, or toolbar, or will display information in a similar fashion. No need to
do the same thing in multiple places; declare a class called Screen, then
extend that class for each screen in your app.


Maybe your video game will have a bunch of different types of heroes and
enemies, all of which can deal damage, take damage, die, revive, party up,
use abilities, etc. You can model your code carefully using classes and
inheritance to minimize how huge and confusing your codebase can
become.
How do inheritance?
I’ll start really simple for our first example.
class
Meme {
}
Inheritance, we did it!
Wait, what…who is inheriting what? That looks like an empty class.
Plot twist! Every single class we’ve made so far has inherited from another
class: java.lang.Object !
You could explicitly inherit from the Object class for no reason, if you
wanted to.

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