Java Reference
In-Depth Information
7. FileOutputStream fos =
8. new FileOutputStream(“a.ser”);
9. new ObjectOutputStream(fos).writeObject(ref);
10. FileInputStream fis =
11. new FileInputStream(“a.ser”);
12. A ref2 = (A)
13. new ObjectInputStream(fis).readObject();
14. System.out.print(ref2.a);
15. }
16. }
17.
18. class A implements Serializable {
19. public int a;
20.
21. public A(int a) {
22. this.a = a;
23. System.out.print(“A”);
24. }
25. }
A.
A0
B.
AA12
C.
A12
D.
An exception is thrown at runtime because the A class does not have a no-argument
constructor.
E.
The code does not compile because the A class does not properly implement the Seri-
alizable interface.
17.
What is the result of the following code?
4. NumberFormat n =
5. NumberFormat.getPercentInstance(Locale.US);
6. double d = 3.1415;
7. System.out.println(n.format(d));
A.
314%
B.
3.1415%
C.
314.15%
D.
3.14%
E.
The code does not compile.
Search WWH ::
Custom Search