What is Polymorphism?
Polymorphism in PHP5 is a technique where the function to be called is detected based on the class object calling it at runtime. The basis of Polymorphism is Inheritance and function overridden.
Example – Basic Polymorphism
class BaseClass
{
public function myMethod()
{
echo "BaseClass method called";
}
}
class DerivedClass extends BaseClass
{
public function myMethod()
{
echo "DerivedClass method called";
}
}
function processClass(BaseClass $c)
{
$c->myMethod();
}
$c = new DerivedClass();
processClass($c);
Output:
DerivedClass method called
Here i am declaring BaseClass and DerivedClass but i am calling the the processClass with the Derived Class Object.
Tuesday, April 20, 2010
PHP OOPS - Polymorphism
Subscribe to:
Post Comments (Atom)


5 comments:
成功等於目前,其他都是這句話的註解。........................................
ut聊天77p2p85cc85st85街視訊視訊聊天ava片a片下載成人情色色情影音視訊聊天洪爺影城洪爺免費視訊免費a片免費一對多utsogo論壇ut聊天室成人片免費看................
先告訴自己希望成為什麼樣的人,然後一步一步實踐必要的步驟。........................................
朝著既定的目標走,就不會迷失。 ..................................................
人間好話,要如海綿遇水牢牢吸住...............................................................
Post a Comment