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.
About Question enthuware.ocpjp.v8.2.1620 :
Moderators: Site Manager, fjwalraven
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1620 :
If you like our products and services, please help us by posting your review here.
-
- Posts: 25
- Joined: Thu Jun 01, 2017 2:50 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1620 :
Thanks Paul (though I realise the real exam might have ambiguities anyway )
-
- Posts: 13
- Joined: Wed Jun 14, 2017 1:56 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1620 :
For me it is not clear yet about this 'f4'
The following snippet shows it is okay if we just change constant value:
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,
What if the code was changed?Which fields of the above class will be have the same values ...
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";
}
Tested on build 1.8.0_45-b15
But, of course,
should meant that this class remains untouched, yeah?the above class
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1620 :
That is correct. No change in class code.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 59 guests