This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
Super

Super 


 

Super {( param {; param2 ; ... ; paramN} )} -> Function result 
Parameter Type   Description
param  Mixed in Parameter(s) to pass to the parent constructor
Function result  Object in Object's parent

The Super command makes calls to the superclass. 

Super has been introduced to serve two different purposes:

  • inside a constructor codeSuper is a command that allows to call the constructor of the superclass. When used in a constructor, the Super command appears alone and must be used before the This keyword is used. 
    • If all class constructors in the inheritance tree are not properly called, error -10748 is generated. It's 4D developer to make sure calls are valid. 
    • If the This command is called on an object whose superclasses have not been constructed, error -10743 is generated. 
    • If Super is called out of an object scope, or on an object whose superclass constructor has already been called, error-10746 is generated.

  // inside myClass constructor
 C_TEXT($1;$2)
 Super($1//calls superclass constructor with a text param
 This.param:=$2 // use second param

  • inside a class member functionSuper designates the prototype of the superclass and allows to call a function of the superclass hierarchy.

 Super.doSomething(42) //calls "doSomething" function declared in superclasses

This example illustrates the use of Super in a class constructor. The command is called to avoid duplicating the constructor parts that are common between Rectangle and Square classes.

  //Class: Rectangle
 
 Class constructor
 C_LONGINT($1;$2)
 This.name:="Rectangle"
 This.height:=$1
 This.width:=$2
 
 Function sayName
 ALERT("Hi, I am a "+This.name+".")
 
 Function getArea
 C_LONGINT($0)
 $0:=This.height*This.width

 

  //Class: Square
 
 Class extends Rectangle
 
 Class constructor
 C_LONGINT($1)
 
  // It calls the parent class's constructor with lengths
  // provided for the Rectangle's width and height
 Super($1;$1)
 
  // In derived classes, Super must be called before you
  // can use 'This'
 This.name:="Square"

 

This example illustrates the use of Super in a class member method. 

You created the Rectangle class with a function:

  //Class: Rectangle
 
 Function nbSides
 C_TEXT($0)
 $0:="I have 4 sides"

You also created the Square class with a function calling the superclass function:

  //Class: Square
 
 Class extends Rectangle
 
 Function description
 C_TEXT($0)
 $0:=Super.nbSides()+" which are all equal"

Then you can write in a project method:

 C_OBJECT($square)
 C_TEXT($message)
 $square:=cs.Square.new()
 $message:=$square.description() //I have 4 sides which are all equal



See also 

cs
This

 
PROPERTIES 

Product: 4D
Theme: Language
Number: 1706

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v18 R3

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)