Static Methods v13
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 within the emp_obj_type type
, you can write:
A static method does not have access to, and cannot change the attributes of an object instance, and does not 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:
Within the static function get_dname
, there can be no references to 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 is not 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
).