PLSQL Tip: How to call the parent class overloaded in the subclass

xiaoxiao2021-03-06  40

In C and Java, this is very easy to implement C is: parent class name :: is overloaded (parameter table), such as: AncestorClass :: Name ({arguments}); and in Java, you can use Super Instead of the parent class, such as this implementation super.name ({Arguments});

In Oracle 9i Release 2, this function is not implemented, of course, we can use other ways to implement such functions.

Parental class object type Create or Replace Type Parent As Object (RowsID Integer, Member Procedure Printattr, Final Member Procedure Printattr_parent - It is best to add Final to prevent subclays to overload this method) NOT FINAL; /

Create or Replace Type Body Parent Is Member Procedure Printattr Is Begin Printattr_parent;

Final Member Procedure Printattr_parent is beginning.printattr; - This sentence is a wrong place, throws Identifier 'Super.printattr' Must Be Declared. There is a deletion. DBMS_OUTPUT.PUT_LINE ('parent class method, rowsid: =' || rowsid); end; end; /

Submount Type Create or Replace Type Child under Parent (Overriding Member Procedure Printattr) Not final; /

Create or Replace Type Body Child Is Overriding Member Procedure Printattr Is Begin DBMS_OUTPUT.PUT_LINE ('Subclass Procedure --- Before the parent class process "); - here we have to use Self.printattr, because printattr is not directly Procedures defined in the class Self.printattr; dbms_output.put_line ('subclass process --- After calling the parent class "); end; end; /

Then we test: Declare vParent Parent: = Parent (1); vchild child: = child (11); begin dbms_output.put_line ('Run the parent process'); vparent.printattr; dbms_output.put_line (' Run Subclass Process'); Vchild.printattr; End;

operation result:

Run the parent class process parent class method, RowsId: = 1 Run Subclass Process Subclass Procedure --- Call the parent class method, rowsid: = 11 Subclass process --- After calling the parent class process

Although this is a bit trouble, the parent class has several reloaded methods, you will add a few other methods in the parent parent. But there is no way, 'curve saving the country'.

转载请注明原文地址:https://www.9cbs.com/read-66919.html

New Post(0)