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
How to avoid the undefined index error?
Define object-oriented methodology?
What is string and its function?
Is a number php?
Tell me how is it possible to remove escape characters from a string?
What is the difference between print() and echo()?
Tell me how can we determine whether a variable is set?
How to write the form tag correctly for uploading files?
Why is facebook still using php?
Explain Whitespace Characters?
How is the comparison of objects done in php?
How do you use bcrypt for hashing passwords in php?
Do you know what is the use of rand() in php?
What does $_env means?
What is php and why it is used?