About Question enthuware.ocpjp.v8.2.1753 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Perelun
Posts: 5
Joined: Sat Jul 06, 2019 7:10 am
Contact:

About Question enthuware.ocpjp.v8.2.1753 :

Post by Perelun »

Answer n. 3 "When deserializing an object, the no-argument constructor each of its super classes that does not implement Serializable interface is invoked." is considered wrong because "The no-argument constructor of only the first non-serializable super class is invoked. This constructor may internally invoke any constructor of its super class."

It seems to me a little misleading because a constructor always invokes the super constructor. Infact, if the call to the super constructor is not explicitly done, the java compiler automatically adds a call to the no-argument super constructor. So it is not true that a constructor "may" internally invoke any constructor of its super class, because it does it always. So if the first non-serializable class constructor is invoked, then also all its super constructors will be indirectly invoked.
And so the answer number 3 seems to me correct.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by admin »

The option is talking about the no-args constructor. It is not necessary that the no-args will always be invoked.
If you like our products and services, please help us by posting your review here.

radionoise
Posts: 2
Joined: Thu Sep 19, 2019 5:19 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by radionoise »

I don't get it. Why it is not necessary that the no-args will always be invoked? Superclass constructor is explicitly called when super() is not present.

Code: Select all

class A {
    public A() {
        System.out.print("A");
    }
}

class B extends A {
    public B() {
        System.out.print("B");
    }
}

class C extends B implements Serializable {
    public C() {
        System.out.print("C");
    }
}
If you will try to deserialize C, you will get the following output: "AB" which proves that A constructor was invoked implicitly when invoking the B constructor.

Do you mean that B constructor could invoke any other A constructor with arguments (if any) resulting in no-arg A constructor will not be invoked?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by admin »

Correct. As the explanation says: The no-argument constructor of only the first non-serializable super class is invoked. This constructor may internally invoke any constructor of its super class.
If you like our products and services, please help us by posting your review here.

steinov
Posts: 19
Joined: Wed Feb 08, 2023 3:11 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by steinov »

Why is it that readObject is invoked before deserialization and not after? Is it because it is part of the deserialization process and therefore it is by definition before (or I would rather say during)? Or is this specified somewhere in the JavaDoc (I couldn't find it).
And is writeObject invoked before or after serialization?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by admin »

Not sure I understand your question. When you say "deserialization" what do you mean? There is no single specific step called deserialization. Deserialization is a process and readObject is a part of it.
If you like our products and services, please help us by posting your review here.

steinov
Posts: 19
Joined: Wed Feb 08, 2023 3:11 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by steinov »

I think that's also where my confusion comes from. The question has (i.a.) the following two answers:
The readObject method will be invoked after a Data object is deserialized.
The readObject method will be invoked before a Data object is deserialized.
According to the answers the second answer (invoked before) is correct and the first (invoked after) is not. If, like you said, the readObject method is part of the deserialization process, the answers are a bit ambiguous and should be changed maybe?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by admin »

readObject is called during the process of deserialization, so the first option is definitely incorrect. The second option is correct because until this method is called the process of deserialization is not complete.
If you like our products and services, please help us by posting your review here.

Mekh17
Posts: 1
Joined: Mon May 15, 2023 8:12 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1753 :

Post by Mekh17 »

Please, who can help me to buy OCA exam here. i want to buy buy my order is cancelled.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 35 guests