Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching.

Similar presentations


Presentation on theme: "Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching."— Presentation transcript:

1 Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching

2 ChessPiece bishop; bishop Object : instance of ChessPiece “having many forms” Polymorphic reference can refer to different types of objects at different points in time

3 Obj.doIt(); //if obj is polymorphic In the loop In a method Commitment is made to execute certain code to carry out a method invocation : binding a method invocation to a method definition Compile time binding vs. run time binding polymorphic reference late binding / dynamic binding via inheritance / interface

4 Polymorphism via Inheritance Class name reference variable; Reference variable can refer to any object of that class related to its declared type by inheritance mammal pet; horse secretariat = new Horse(); pet = secretariat; animal creature = new Horse();creature.move(); Object reference?

5 Firm has 3 different staff members Volunteer, Employee( Executive, Hourly) Employee: name address phone Employee: + ssn payrate Executive: + bonus Houlry = - bonus + hours worked

6

7 3 9 1 6 2 11 2 1 2 3 6 1 2 3 6 1 2 3 9 Selection Insertion quick

8 3 9 1 6 2 3 9 1 6 2 1 9 3 6 2 1 9 3 6 2 1 2 3 6 9 1 2 3 6 9 1 2 6 3 9 1 2 6 3 9

9 3 9 1 6 2 temp = myarray[2]; myarray[2] = myarray[1]; myarray[1] = temp; 3 6 1 9 2 temp = myarray[3]; Myarray[1]=myarray[0]; myarray[2] = myarray[1]; myarray[3] = myarray[2]; Myarray[0] = temp

10 Sort and search - Insertion, selection, quick, merge - Linear search, binary search

11


Download ppt "Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching."

Similar presentations


Ads by Google