What is the result?
A.
M001, ,
B.
M001, null, null
C.
M001, Sam,
D.
M001, Sam, null
E.
M001, Sam, ABC Inc (Frage unvolständig!!!)
F.
Compilation fails
G.
A NullPointerException is thrown at runtime
Explanation:
What is the result?
A.
M001, ,
B.
M001, null, null
C.
M001, Sam,
D.
M001, Sam, null
E.
M001, Sam, ABC Inc (Frage unvolständig!!!)
F.
Compilation fails
G.
A NullPointerException is thrown at runtime
Explanation:
This question is incomplete.
the question is incomplete, don’t bother urslf with it
It is B because only Manager implements serializable interface.
public class Employee {
String name;
transient String companyName;
}
public class Manager extends Employee {
String mgrId;
public String toString() {
return mgrId + ” ” + name + ” ” + companyName;
}
}
public class SerializableTest {
public static void main(String[] args) throws Exception {
Manager mgr = new Manager();
mgr.companyName = “ABC Inc”;
mgr.name = “Sam”;
mgr.mgrId = “M001”;
System.out.println(mgr.toString());
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
“c:/temp/mgr.ser”));
oos.writeObject(mgr);
oos.close();
mgr = null;
System.out.println(“mgr = ” + mgr);
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
“c:/temp/mgr.ser”));
mgr = (Manager) ois.readObject();
ois.close();
System.out.println(mgr.toString());
}
}
It Must be D, only transient properties of Object will not be maintain the state when we write into stream. hence Name and ID will be Sam and M001 but companyName will be null;