About Question enthuware.ocpjp.v8.2.1753 :
Moderator: admin
-
- Posts: 5
- Joined: Sat Jul 06, 2019 7:10 am
- Contact:
About Question enthuware.ocpjp.v8.2.1753 :
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.
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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.
-
- Posts: 2
- Joined: Thu Sep 19, 2019 5:19 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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.
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?
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");
}
}
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?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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.
-
- Posts: 19
- Joined: Wed Feb 08, 2023 3:11 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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?
And is writeObject invoked before or after serialization?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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.
-
- Posts: 19
- Joined: Wed Feb 08, 2023 3:11 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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.
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?The readObject method will be invoked before a Data object is deserialized.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
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.
-
- Posts: 1
- Joined: Mon May 15, 2023 8:12 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1753 :
Please, who can help me to buy OCA exam here. i want to buy buy my order is cancelled.
Who is online
Users browsing this forum: No registered users and 112 guests