Inheritance in OOP
Posted by Raj
Inheritance in OOP :
In this tutorial we will study about Inheritance.- Inheritance is a mechanism of extending an existing class.
- In Inheritance child class inherits all the functionality of Parent Class.
For example, when you extend a class, the subclass inherits all of the public and protected methods from the parent class. Unless a class overrides those methods.
<?php
class BaseClass
{
public function GetValue($string)
{
echo 'BaseClass:'. $string ;
}
public function setValue($string)
{
echo $string;
}
}
class ChildClass extends BaseClass
{
public function GetValue($string)
{
echo 'ChildClass:'. $string ;
}
}
$b = new BaseClass();
$c = new ChildClass();
$b->GetValue('Rajesh Test'); // Output: 'BaseClass: Rajesh Test'
$b->setValue('Rajesh Test'); // Output: 'Rajesh Test'
$c->GetValue('Rajesh Tutorials'); // Output:'ChildClass: Rajesh Tutorials'
$c->setValue('Rajesh Test'); // Output: 'Rajesh Test'
?>
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
inheritance in OOP,
inheritance oop,
inheritance php,
oop inheritance,
OOP interview questions and answers,
PHP,
php classes,
PHP interview questions and answers,
php oop,
programming php
.You can leave a response, or trackback from your own site.