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



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

Order of execution :
static blocks of super classes
static blocks of the class
init blocks of super classes
constructors of super classes
init blocks of the class
constructors of the class
1. The code in static initialization block will be
executed at class load time (and yes, that means
only once per class load), before any instances of
the class are constructed and before any static
methods are called.
2. The instance initialization block is actually copied by
the Java compiler into every constructor the class
has. So, the code in instance initialization block is
executed exactly before the code in constructor.
Question 50: What is called first, constructor or init
block?
Answer: Constructor is invoked first. Compiler copies all the code of
instance initializer block into the constructor after first statement
super().
Question 51: What is Variable shadowing and
Variable hiding in Java?
Answer: Variable shadowing : When a local variable inside a
method has the same name as one of the instance variables, the
local variable shadows the instance variable inside the method
block.
Example 1:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
51\Variable Shadowing\Example 1\color.png


Output:
C:\Users\jja
tin\Desktop\D
ifferent
Versions\All_
Photos\Ques
tion
51\Variable
Shadowing\E
If you want to access instance variables then you can do so using
‘this’ keyword like below:
Example 2:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
51\Variable Shadowing\Example 2\color.png


Output:
C:\Users\jja
tin\Desktop\D
ifferent
Versions\All_
Photos\Quest
ion
51\Variable
Shadowing\E
Variable Hiding : When the child and parent classes both have a
variable with the same name, the child class variable hides the
parent class variable.
Example 1:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
51\Variable Hiding\Example 1\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
51\Variable Hiding\Example 1\color2.png


Output:
C:\Use
rs\jjatin\
Desktop\
Different
Versions
If you want to access parent’s class variable then you can do this
using super keyword:
Example 2:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
51\Variable Hiding\Example 2\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
51\Variable Hiding\Example 2\color2.png


Output:
C:\Users\
jjatin\Deskt
op\Differen
t
Versions\Al
l_Photos\Q
uestion

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   25   26   27   28   29   30   31   32   ...   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