Calling Constructors:
The Calls to a constructor are allowed wherever the function calls are allowed. Similarly to the functions, a constructor is called as a section of an expression, as the illustration below is a shown:
DECLARE
r1 Rational := Rational(2, 3);
FUNCTION average (x Rational, y Rational) RETURN Rational IS
BEGIN
...
END;
BEGIN
r1 := average(Rational(3, 4), Rational(7, 11));
IF (Rational(5, 8) > r1) THEN
...
END IF;
END;
Whenever you pass a parameter to a constructor, the call assigns its initial value to the attributes of the object being instantiated. You should supply a parameter for every attribute as, dissimilar constants and variables, the attributes cannot have the default values. As the illustration shown below, the nth parameter assigns a value to the nth attribute:
DECLARE
r Rational;
BEGIN
r := Rational(5, 6); -- assign 5 to num, and 6 to den
-- now r is 5/6
The later illustration shows that you can call a constructor using the named notation rather than that of the positional notation:
BEGIN
r := Rational(den => 6, num => 5); -- assign 5 to num, and 6 to den