Answer Posted / 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 |
Post New Answer View All Answers
Explain the difference between static and dynamic websites?
Which is faster for or foreach php?
What is difference between action hook and filter hook?
What is php and what does it do?
What does the unset() function mean?
What is return value in php?
What does a delimiter do in mysql?
How do I sort numbers in php?
What is the function to count elements in an array in PHP?
What is the use of $_server and $_env?
What is session_register()?
What is full form of php? Who is the father or inventor of php?
Which method removes the last element from the end of an array?
Is it possible to destroy a cookie?
What is csrf validation?