My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 26, 2009 by r.parlett
SpecialMethods  
About the new and init methods.

Special methods

There are two special methods, which are used to initialize a class and its objects.

The init() method

The init() method is used to initialize a class, and in particular to initialize the values of any static variables. It is called automatically the first time that one of the class's (static) fields is accessed, or when an instance of the class is created.

Some other points to note about init() :-

The new() method

The new method is used to initialize an object, ie an instance of a particular class. The method is not invoked explicitly however. Rather, in order to create an instance the class name is used like a function call, and the new() method is invoked automatically. So for example :-

import io

class X()
   public new(a, b)
      write("in new a=", a, " b=", b)
      return
   end
end

procedure main()
   local i
   i := X(3, 4)
end

This writes "in new a=3 b=4".

Some other points to note about new() :-


Sign in to add a comment
Hosted by Google Code