Static methods v16
Like a member method, a static method belongs to a type. A static method, however, is invoked not by an instance of the type, but by using the name of the type. For example, to invoke a static function named get_count
, defined in the emp_obj_type type
, you can write:
A static method doesn't have access to and can't change the attributes of an object instance. It doesn't typically work with an instance of the type.
The following object type specification includes a static function get_dname
and a member procedure display_dept
:
The object type body for dept_obj_typ
defines a static function named get_dname
and a member procedure named display_dept
:
The static function get_dname
can't reference SELF
. Since a static function is invoked independently of any object instance, it has no implicit access to any object attribute.
Member procedure display_dept
can access the deptno
attribute of the object instance passed in the SELF
parameter. It isn't necessary to explicitly declare the SELF
parameter in the display_dept
parameter list.
The last DBMS_OUTPUT.PUT_LINE
statement in the display_dept
procedure includes a call to the static function get_dname
, qualified by its object type name dept_obj_typ
.