This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
Super
|
Super {( param {; param2 ; ... ; paramN} )} -> Function result | ||||||||
Parameter | Type | Description | ||||||
param | Mixed |
![]() |
Parameter(s) to pass to the parent constructor | |||||
Function result | Object |
![]() |
Object's parent | |||||
The Super command makes calls to the superclass.
Super has been introduced to serve two different purposes:
// inside myClass constructor
C_TEXT($1;$2)
Super($1) //calls superclass constructor with a text param
This.param:=$2 // use second param
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
Product: 4D
Theme: Language
Number:
1706
Created: 4D v18 R3
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)