27 lines
701 B
Plaintext
27 lines
701 B
Plaintext
class [static] ARootClass{ // A top level class, no instances
|
|
class A{ self.println(" constructor"); } // a regular class
|
|
class B(A){ // ditto
|
|
var x;
|
|
fcn init(x=123){ self.x=x }
|
|
fcn toString{ "x is "+x }
|
|
}
|
|
}
|
|
|
|
ARootClass.B(456).println(); // create an instance
|
|
// prints:
|
|
Class(A) constructor
|
|
x is 456
|
|
|
|
f:=File("object.dat","wb");
|
|
Compiler.Asm.writeRootClass(ARootClass,f); // serialize to file
|
|
f.close();
|
|
|
|
f:=File("object.dat","rb");
|
|
rc:=Compiler.Asm.readRootClass(f); // read and re-create
|
|
// prints (readRootClass calls all constructors by default):
|
|
Class(A) constructor
|
|
f.close();
|
|
rc.B().println(); // create a new instance of B
|
|
// prints:
|
|
x is 123
|