What is inheritance in php progaming?
Answer / 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 |
What is the use of htmlentities in php?
What backslash character will match whitespace?
What is php addslashes?
What is the use of trim function in php?
List the different types of print functions available in php?
Why overriding is called runtime polymorphism?
Do you know what is the difference between the include() and require() functions?
How we get ip address of client, previous reference page etc?
Is php a float?
What is prepare in php?
How can we automatically escape incoming data?
What is PEAR?