About Question enthuware.ocpjp.v8.2.1752 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Robbie
Posts: 13
Joined: Sun Mar 27, 2016 1:10 pm
Contact:

About Question enthuware.ocpjp.v8.2.1752 :

Post by Robbie »

Answer A reads: To customize the behavior of class serialization, the readObject and writeObject methods should be overridden.

Since the readObject and writeObject methods are not in any interface technically you are not overriding any methods?

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

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

Post by admin »

Not sure what you mean. If these were in an interface, you would "implement" them, not "override" them. It is precisely because these methods belong to a class (ObjectInputStream), you would override them.
Here is what the JavaDoc for this method says:
Default deserializing for a class can be overriden using the writeObject and readObject methods.
.

Robbie
Posts: 13
Joined: Sun Mar 27, 2016 1:10 pm
Contact:

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

Post by Robbie »

If these were in an interface, you would "implement" them, not "override" them.
Well when you implement an interface method in a concrete class you can still use the @Override annotation so technically it still is an override or at least Java seems to see it that way.

But in the case of ObjectInputStream yes it would indeed be an override.

However there is another case where in the actual object you are serializing you can add two methods:

Code: Select all

private void writeObject(ObjectOutputStream os) { }
private void readObject(ObjectInputStream is) { }
In question enthuware.ocpjp.v8.2.1389 in the explanation of the last answer there is an example of this approach.

Those methods will get called automatically if they exist but they are not in any interface so it is not an override.

To me it is not clear if answer A means the methods in ObjectInputStream which would be an override or the methods in the actual object you are serializing which would not be an override and you can use both to custimize the serialization behavior.

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

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

Post by admin »

OK, I see what you mean. Will make the option clear about what it means. In general though, if you see a method name, and if it is same as the one that belongs to a known standard class, you should assume it to be of that class instead of assuming it being a user defined method.

-Paul.

RAZER-KIEV
Posts: 17
Joined: Thu Oct 01, 2015 4:06 pm
Contact:

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

Post by RAZER-KIEV »

In other question (enthuware.ocpjp.v8.2.1389) it was used another explanation "Make bonds array transient in Portfolio and IMPLEMENT readObject and writeObject methods to read and write the state of Bond objects explicitly." it makes me confused too.

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

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

Post by admin »

Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests