About Question enthuware.ocpjp.v8.2.1620 :

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
admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

I have updated the problem statement to, "Which fields of the above class will be have the same values ..." instead of "preserved". That should make it very clear :)

thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Cannelids
Posts: 25
Joined: Thu Jun 01, 2017 2:50 pm
Contact:

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

Post by Cannelids »

Thanks Paul (though I realise the real exam might have ambiguities anyway 8-) )

ssszzz
Posts: 13
Joined: Wed Jun 14, 2017 1:56 pm
Contact:

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

Post by ssszzz »

For me it is not clear yet about this 'f4'
Which fields of the above class will be have the same values ...
What if the code was changed?
The following snippet shows it is okay if we just change constant value:

Code: Select all

public class Test35 {

    public static void main(String... strings) throws IOException, ClassNotFoundException {
        String file = "./test.data";
        /*Data d = new Data();
        d.f1 = "f1";
        d.f2 = 2;
        d.f3 = true;
        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file))) {
            out.writeObject(d);
        }*/
        Data d2 = null;
        try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) {
            d2 = (Data) in.readObject();
        }
        System.out.println(d2);
    }
}

class Data implements java.io.Serializable {
    public static String f1;
    public static transient int f2;
    public transient boolean f3;
    public final static String f4 = "442";
    public String f5 = "5";
}
But if we comment out line 'public final static String f4' or change variable name then we get exception while deserialization about 'serialVersionUID' as expected.
Tested on build 1.8.0_45-b15

But, of course,
the above class
should meant that this class remains untouched, yeah?

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

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

Post by admin »

That is correct. No change in class code.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests