Student Of Fortune

PHP And Class Part3 (Overriding)

Share on :
hIf in the previous article I have discussed classes and inheritance (Inheritance), then in the third article I will discuss about Overriding. What is Overriding? Sometimes in a program, we are confused to give a variable name. In procedural programming, we can not use the same variables repeatedly. But the concept of OOP, we can use the same variables repeatedly but the operation performed by different methods. This is called Overriding.

For more details, let's look at a simple example of overriding concept below:

class parent {
var $ word = "Print the parent";
function word () {
print $ this-> word;
}
}
class child extends parent {
var $ word = "Print
child";
function word () {
print $ this-> word;
}
}
$ print = new child ();
$ print-> word ();
?>

The result: Print child.

Why are displayed on the screen is the word "print child"instead of inheriting parent class requires the "print parent"? Because the class child occurred in method overriding said. Hence, in the run, which is displayed on the screen print is not a parent but "print child". So first explanation from me. Hopefully all your friends to know and understand.
 

0 comments on PHP And Class Part3 (Overriding) :

Post a Comment and Don't Spam!

Dont Spam please

 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank