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
What is the use of trim function in php?
What is interface? Why it is used?
Explain how can we execute a php script using command line?
How to pass variables by references?
Explain how can php and javascript interact?
What is a http session?
Which is variable cost?
What are the different types of array in php?
What is the static variable in function useful for?
CWD is a type of shell variable. State Whether True or False?
Is it possible to destroy a cookie?
What is strcmp () in php?
With a heredoc syntax, do I get variable substitution inside the heredoc contents?
Explain what is memcache?
How is it possible to remove escape characters from a string?