Hi, The LRM says, "Every class has a default (built-in) new method. The default constructor first calls its base class constructor (super.new() as described in 8.14) and then proceeds to initialize each member of the current object to its default (or uninitialized value)." and "When using the super within new, super.new shall be the first statement executed in the constructor. This is because the superclass shall be initialized before the current class and, if the user code does not provide an initialization, the compiler shall insert a call to super.new automatically." and "When a subclass is instantiated, the class method new() is invoked. The first action that new() takes, before any code defined in the function is evaluated, is to invoke the new() method of its superclass and so on up the inheritance hierarchy. Thus, all the constructors are called, in the proper order, beginning with the root base class and ending with the current class. If the initialization method of the superclass requires arguments, there are two choices: to always supply the same arguments or to use the super keyword. If the arguments are always the same, then they can be specified at the time the class is extended: class EtherPacket extends Packet(5); This passes 5 to the new routine associated with Packet. A more general approach is to use the super keyword, to call the superclass constructor: function new(); super.new(5); endfunction To use this approach, super.new(...) shall be the first executable statement in the function new." This leaves some cases unclear. The Doulos SV Golden Reference Guide says the following, "If the new() function of a subclass is overridden, it does not call the parent class's constructor by default. This will almost always need to be called explicitly as the first statement in the overloaded constructor." Is this correct? It is certainly not clear from the LRM. For example, the last section quoted from the LRM implies that if I wrote, class EtherPacket extends Packet(5); then it is not necessary to call "super.new(5)" in EtherPacket.new. The Doulos statement means that if EtherPacket has a user-defined new(), then it still requires "super.new(5)" (or just "super.new"?) Related is Mantis 2358. Thanks, Shalom Shalom Bresticker Intel Jerusalem LAD DA +972 2 589-6582 +972 54 721-1033 --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Thu Feb 12 04:55:53 2009
This archive was generated by hypermail 2.1.8 : Thu Feb 12 2009 - 04:56:37 PST