• Post Reply Bookmark Topic Watch Topic
  • New Topic

a question about Object Url.

 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this is a mock xam question.
import java.io.*;
import java.net.*;
class Class1 implements Serializable {
String name, address;
URL url;
public Class1(String n,String a,int p) {
name = n;
address = a;
url = new URL("http://domain:" + p);
}
additional code here
How can you prevent object "url" from being saved to file when storing a Class1 object using java serialization?
1 declare "url" as transient
2 make Class1 abstract
3 implement Externalizable and create a writeObject() method
4 store "url" in another class and reference it from Class1
5 declare "url" as either static or final
could anybody please tell what the right answer is and how?.
with warm regards,
arun.
 
Todd Bush
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#1 is correct. To keep any variables or object references from saving with a serialized object, declare them as trasient.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!