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 read one character from a file?
What is the difference between $name and $$name?
What is a simple php method to make a cross domain data request?
Suppose your zend engine supports the mode ?> Then how can you configure your php zend engine to support Mode ?
Explain how is it possible to set an infinite execution time for php script?
What is default session time in php?
What is the purpose of $_ session?
What is the difference between myisam and innodb?
What is csrf token and how it works?
How to create a session? How to set a value in session?
Can we use get instead of post?
Explain the casts allowed in PHP?
What are include() and require() functions?
How to execute an sql query?
What is env in laravel?