polymorpihsm ->one name, many form.
have 2 types : 1. Compile time, 2 Run time
1 compile time: also called overloading
have 3 types. 1. Constructor overloading(i.e.,with same constructor name and different no of arguments or different datat types or both ) 2 Function overloading(i.e.,with same function name and different no of arguments or different datat types or both)
3. operator overloading: exaample : String s = "James";
s = s + "Bond";
Runtime poly: is achieved by overridding parent class method:
This is called Dynamic method dispatch.
1. function overloading,
2. Runtime polymorphism --Using Interface reference,
EX:
interface name I ,abstract Method();
implimenting classes A,B
ref I;
objA= new A();
objB= new B();
runtime
objA=I
objA.Method();
objB=I;
objB.Method();
Polymorphism comes in to action with dynamic binding, so it's important to identify which object to have which behavior. (VB.net and C# both are default to dynamic binding)
No comments:
Post a Comment