Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview


Question 48: What is Constructor Chaining in java?



Download 7,31 Mb.
Pdf ko'rish
bet27/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   23   24   25   26   27   28   29   30   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

Question 48: What is Constructor Chaining in java?
Answer: when one constructor calls another constructor, it is known
as constructor chaining. This can be done in two ways:
this() : it is used to call the same class constructor
super() : it is used to call the parent class
constructor
this() Example:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
48\this() Example\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
48\this() Example\color2.png


Output:
C:\Users\jjatin\Desktop\Different
Versions\All_Photos\Question 48\this()
Example\output.png


super() example:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
48\super() Example\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
48\super() Example\color2.png


Output:
C:\Users\jjat
in\Desktop\Dif
ferent
Versions\All_
Photos\Quest
ion 48\super()
Example\outp
ut.png
Some points to remember:
this() can call same class constructor only
super() can call immediate super class constructor only
this() and super() call must be the first statement,
because of this reason both cannot be used at the same
time
you must use super() to call the parent class constructor
but if you do not provide a super() call, JVM will put it
automatically

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   23   24   25   26   27   28   29   30   ...   89




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