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 a controller in programming?
Hello Friends,I am seeking for a job in php having 9 months. exp.Please suggest any company openings.
How do I end a php session?
Which is better wamp or xampp?
Why do we use in php?
How escape single quotes php?
What is __ construct in php?
What is a base url?
How do I get csrf token?
What is the difference between echo print and print_r in php?
What does $_env means?
Explain the difference b/w static and dynamic websites?
What is cakephp framework?
What do you mean range() in php?
What are php variables?