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


- If a parent class has implemented Serializable interface then child class doesn’t need to implement it but the reverse is not true -



Download 7,31 Mb.
Pdf ko'rish
bet37/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   33   34   35   36   37   38   39   40   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

If a parent class has implemented Serializable interface
then child class doesn’t need to implement it but the
reverse is not true
Static data members and transient data members are
not saved via Serialization process (serialVersionUID is
an exception). So, if you don’t want to save value of a
non-static data member then make it transient
Constructor of serialized class is never called when the
serialized object is deserialized (in case of inheritance,
no-arg constructor of parent gets called during de-
serialization)
Question 58: Serialization scenarios with
Inheritance
Case 1: If super class is Serializable then by default, its sub-classes
are also Serializable


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 1\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 1\color2.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 1\color3.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 1\color4.png


Output:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 1\output.png


Case 2: When super class does not implement the Serializable
Interface, then also we can serialize the subclass provided that it
implements Serializable interface.
In this case, when we de-serialize the subclass object, then no-arg
constructor of its parent class gets called. So, the serializable sub-
class must have access to the default no-arg constructor of its parent
class (general rule is that the Serializable sub-class must have
access to the no-arg constructor of first non-Serializable super
class).


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 2\color1.png


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 2\color2.png


(Note: serializeObject() and deserializeObject() remains same as the
Case 1 program)
Output:


C:\Users\jjatin\Desktop\Different Versions\All_Photos\Question
58\Case 2\error.png



Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   33   34   35   36   37   38   39   40   ...   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