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?
About Question enthuware.ocpjp.v8.2.1752 :
Moderators: Site Manager, fjwalraven
-
- Posts: 13
- Joined: Sun Mar 27, 2016 1:10 pm
- Contact:
-
- Site Admin
- Posts: 10387
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1752 :
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:
Here is what the JavaDoc for this method says:
.Default deserializing for a class can be overriden using the writeObject and readObject methods.
-
- Posts: 13
- Joined: Sun Mar 27, 2016 1:10 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1752 :
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.If these were in an interface, you would "implement" them, not "override" them.
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) { }
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.
-
- Site Admin
- Posts: 10387
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1752 :
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.
-Paul.
-
- Posts: 17
- Joined: Thu Oct 01, 2015 4:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1752 :
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.
-
- Site Admin
- Posts: 10387
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1752 :
Fixed.
thank you for your feedback!
thank you for your feedback!
Who is online
Users browsing this forum: No registered users and 12 guests