What is inheritance in php progaming?
Answer / dhanya
Inheritance is the extension of a class. A child class has
all the properties and methods of its parent class. For
example, pets generally share similar characteristics,
regardless of what type of animal they are. Pets eat, and
sleep, and can be given names. However the different types
of pet also have their own methods: dogs bark and cats meow.
Below is an implementation of this:
<?php
class Pet
{
var $_name;
function Pet($name)
{
$this->_name = $name;
}
function eat()
{
}
function sleep()
{
}
}
class Dog extends Pet
{
function bark()
{
}
}
class Cat extends Pet
{
function meow()
{
}
}
$dog = new Dog("Max");
$dog->eat();
$dog->bark();
$dog->sleep();
$cat = new Cat("Misty");
$cat->eat();
$cat->meow();
$cat->sleep();
?>
| Is This Answer Correct ? | 1 Yes | 0 No |
What is php and how do you use it?
What are the __construct() and __destruct() methods in a php class?
What are the differences between session and cookie?
What is the use of addslashes in php?
What is meant by variable variables in php?
my english is not too good then what we apply for a php programer post
What is the function in PHP do not return a timestamp?
What does $globals means?
Why does php start with variables?
What does explode do in php?
What is cookie and session in php?
What is difference between required and include in php?