Lab 10 08122023 040046pm
Lab 10 08122023 040046pm
Objective(s) :
• To learn inheritance , abstraction and method over riding in object.
1. Inheritance
➢ Object types offer inheritance. This means that we can declare an object type to be “under”
another type, and it inherits all the attributes and methods of that super type or base type.
Example:
/* NOT FINAL represents the Base Type. Means Subtype can be created.
NOT INSTANTIABLE means that none of the instance of the Base Type can be created*/
/
2. Method Overriding
➢ Method Overriding is when methods have same prototype in base class as well as derived
class.
➢ Method Overriding occurs when one class is inherited from another class.
➢ Method Overriding is the ability of the inherited class (sub type) rewriting the virtual
method of the base class (base object type).
Example:
Base type (Parent Class) Specification
create or replace type vehicle
as object
(
/*all attributes are comma separated*/
reg_no number,
make varchar2(25),
model date,
member function print return varchar2
)
/* NOT FINAL represents the Base Type. Means Subtype can be created.
NOT INSTANTIABLE means that none of the instance of the Base Type can be created*/
not instantiable not final;
DECLARE
v_car car := car(100, 'toyota', '1-Jan-2017', 1800000, 'Black');
/* v_car is an instance of sub_type Car. Its attributes has been initialized with the CONSTRUCTOR
method */
v_message1 Varchar2(100);
v_message2 Varchar2(100);
BEGIN
v_message1 := (v_car as vehicle).print;
v_message2 := v_car.sub_print;
dbms_output.put_line(v_message1);
dbms_output.put_line(v_message2);
END;
/
3. Abstraction
➢ Abstraction is one of the most essential and important feature of object oriented databases.
➢ Abstraction means displaying only essential information and hiding the details.
Example:
Create a package MY_PACKAGE having a public procedure MUL_TABLE
end;
end my_package;
declare
my_obj my_type:=my_type(2);
begin
my_obj.times_table(2);
end;
Departemnent of Computer Sciences 6/7 Semester Fall 2021
ITC-327: Database Administration & Management Lab 10: Ineritance, Method Overriding and Abstraction
Exercises
Library
ISBN_No
Display member function Title
Books Magazines
Author Mag_no
Subject Mag_month
Book_Display member function
INHERITANCE
1. Create a base object type LIBRARY with following attributes and member function
Attributes:
ISBN_no number
Title varchar2(35)
Member Function:
DISPLAY function must display ISBN_no and title of book/magazine.
2. Create a sub object type BOOKS under base type LIBRARY with following attributes and
overriding member function
Attributes:
Author varchar2(25)
Subject varchar2(25)
3. Create a sub object type MAGAZINES under base type LIBRARY with following attributes
and overriding member function
Attributes:
Mag_no number
Month varchar2(20)
Book’s AUTHOR and its SUBJECT must be displayed through its own
DISPLAY member function.
Similarly Magazine’s MAG_NO and MONTH must be displayed through its
own DISPLAY member function.
ABSTRACTION
5. Using table EMP, create a package which has a public function TOTAL_SAL
and public procedure DISPLAY.
TOTAL_SAL function must take DEPTNO as an input parameter and must
display the total salary of all the managers of that department.
DISPLAY procedure must take MANAGER NO as input parameter and must
display all the employees’ names working under that manager.