Page 1 of 1

About Question enthuware.ocpjp.v8.2.1753 :

Posted: Sat Jul 06, 2019 11:33 am
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.

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

Posted: Sat Jul 06, 2019 11:52 am
by admin
The option is talking about the no-args constructor. It is not necessary that the no-args will always be invoked.

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

Posted: Thu Sep 19, 2019 5:24 am
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?

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

Posted: Thu Sep 19, 2019 5:29 am
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.

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

Posted: Sun Apr 23, 2023 9:57 am
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?

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

Posted: Sun Apr 23, 2023 12:54 pm
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.

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

Posted: Sun Apr 30, 2023 6:05 am
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?

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

Posted: Sun Apr 30, 2023 6:50 am
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.

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

Posted: Mon May 15, 2023 8:17 am
by Mekh17
Please, who can help me to buy OCA exam here. i want to buy buy my order is cancelled.