Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 32

Given the code fragment:

Which fields are serialized in a Student object?

    Correct Answer: C

    In Java serialization, when an object is serialized, all non-transient and non-static fields that belong to the class and its superclasses (as long as they are not marked transient) will be included in the serialization process. In this case, the Student class extends the Person class and implements the Serializable interface. Despite Person not implementing Serializable, the inherited fields from Person will still be considered in the serialization process of Student. Since the name field in the Person class is non-transient, it will be serialized. The classes field in Student will also be serialized because it is an instance of a Serializable class. Therefore, the fields studentNo, classes, and name will all be serialized, while the transient address field in Person will not be. Thus, the correct answer is that the fields studentNo, classes, and name are serialized in a Student object.

Discussion
Mukes877Option: A

A is right

OmnisumemOption: C

In the Student class, the fields that will be serialized are: name (inherited from the Person class) studentNo classes The name field is inherited from the Person class, and since Person is not marked as transient and does not implement Serializable, its name field will be serialized. The studentNo field is directly declared in the Student class and since Student implements Serializable, it will be serialized. The classes field is of type Classes, which also implements Serializable. Therefore, it will be serialized as well. However, the address field from the Person class is marked as transient, which means it will not be serialized.

d7bb0b2Option: C

C is correct, Person is extended by Student so inherit his field an name are marked as seriaziable too

d7bb0b2Option: C

C, cause even Person is not seriazable, Student inherith the field name and then is marked as seriazable, and class and student nro. Note Person class mark transient adress so even Studen inherit thhe fields this is no seriazable.

d7bb0b2Option: C

When a Student object is serialized, the following fields will be included in the serialized form: school from the Student class classes from the Student class, which includes the id field from the Classes class name from the Persona class The address field in the Persona class is marked as transient, which means it will be ignored during serialization and will not be included in the serialized form of a Student object.

[Removed]Option: D

Tested it and answer seems to be D?! Not sure if I did anything wrong but when i made the Person-class implement serielizable as well, then the transient keyword was working as expected but whit no Serializable in the super-class -> the whole class and it's it's members where written down to memory/file reglardless of transient or not.

[Removed]Option: A

Answer is A. Explanation below. Source geeksforgeeks Serialization: At the time of serialization, if any instance variable inherits from the non-serializable superclass, then JVM ignores the original value of that instance variable and saves the default value to the file. De- Serialization: At the time of de-serialization, if any non-serializable superclass is present, then JVM will execute instance control flow in the superclass. To execute instance control flow in a class, JVM will always invoke the default(no-arg) constructor of that class. So every non-serializable superclass must necessarily contain a default constructor. Otherwise, we will get a runtime exception.

StavokOption: C

When an object is serialized, all of its non-transient and non-static fields are serialized, including fields inherited from its superclass. In this case, the Student class extends the Person class and implements the Serializable interface. This means that when a Student object is serialized, all of its non-transient and non-static fields, as well as those of its superclass Person, are serialized. The Student class has two non-transient and non-static fields: studentNo and classes. The classes field is an instance of the Classes class, which also implements the Serializable interface, so it will be serialized along with the Student object. The Person class has one non-transient and non-static field: name. This field is also serialized when a Student object is serialized. The address field in the Person class is marked as transient, so it will not be serialized when a Student object is serialized.

aruni_mishraOption: A

Ans: A When a superclass does not implement Serializable, its attributes are not serialized.

trickeryoyoOption: B

name field should be serialized, too.