COMP2396
Loading...
Searching...
No Matches
notserialsuperclass Class Reference

Static Public Member Functions

static void main (String[] args)
 

Detailed Description

Definition at line 24 of file notserialsuperclass.java.

Member Function Documentation

◆ main()

static void notserialsuperclass.main ( String[] args)
inlinestatic

Definition at line 25 of file notserialsuperclass.java.

25 {
26 if (false) {
27 serializableSubclass a = new serializableSubclass();
28 a.var1_1 = 12; // modify the transient variable
29 a.var1 = 11;
30 a.var2 = 21;
31
32 try {
33 FileOutputStream fos = new FileOutputStream("test.file");
34 ObjectOutputStream oos = new ObjectOutputStream(fos);
35 oos.writeObject(a);
36 oos.close();
37 } catch (Exception ex) {
38 ex.printStackTrace();
39 }
40 } else {
41 serializableSubclass b = null;
42 try {
43 FileInputStream fis = new FileInputStream("test.file");
44 ObjectInputStream ois = new ObjectInputStream(fis);
45 b = (serializableSubclass) ois.readObject();
46 ois.close();
47 System.out.println(b.var1_1);
48 System.out.println(b.var1);
49 System.out.println(b.var2);
50 // output 2,10,21
51 // 2: transient variable default value, not serialized
52 // 10: no-argument constructor
53 // 21: var2 is serialized
54 } catch (Exception ex) {
55 ex.printStackTrace();
56 }
57 }
58 }

The documentation for this class was generated from the following file: