This time I will discuss about the inheritance. Inheritance in OOP or commonly called the Inheritance serves to re-use method of a class that previously had been made. Examples like this, in class A,
use the method Hello. Then in class B, if you want to call methods Hello, you simply called him from class A, without having to recreate it again Hello method. In OOP, Inheritance there are 2 types. Ie single inheritance and multiple Inheritance.
The purpose of the single inheritance is a class child to get a direct descendant of its parent class. While multiple inheritance, class child get an instance of class mother and father. hehe ...:) (confused how the language .... just more than one class.).
use the method Hello. Then in class B, if you want to call methods Hello, you simply called him from class A, without having to recreate it again Hello method. In OOP, Inheritance there are 2 types. Ie single inheritance and multiple Inheritance.
The purpose of the single inheritance is a class child to get a direct descendant of its parent class. While multiple inheritance, class child get an instance of class mother and father. hehe ...:) (confused how the language .... just more than one class.).
An example of inheritance in PHP:
class parent {
var $ parent = "parent";
function parent () {/ / This is the constructor
$ this-> parent;
}
}
class child extends parent {
function child () {
print $ this-> parent;
}
}
$ child = new child ();
?>
class parent {
var $ parent = "parent";
function parent () {/ / This is the constructor
$ this-> parent;
}
}
class child extends parent {
function child () {
print $ this-> parent;
}
}
$ child = new child ();
?>
The result : parent.
0 comments on PHP And Class Part2 (Inheritance) :
Post a Comment and Don't Spam!
Dont Spam please