Polymorphism What is it, why it is needed? Dynamic binding Sorting and searching
ChessPiece bishop; bishop Object : instance of ChessPiece “having many forms” Polymorphic reference can refer to different types of objects at different points in time
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
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?
Firm has 3 different staff members Volunteer, Employee( Executive, Hourly) Employee: name address phone Employee: + ssn payrate Executive: + bonus Houlry = - bonus + hours worked
Selection Insertion quick
temp = myarray[2]; myarray[2] = myarray[1]; myarray[1] = temp; temp = myarray[3]; Myarray[1]=myarray[0]; myarray[2] = myarray[1]; myarray[3] = myarray[2]; Myarray[0] = temp
Sort and search - Insertion, selection, quick, merge - Linear search, binary search