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 php and its uses?
WHat is the diff. between PHP4 and PHP5?
6 Answers Clarion Technologies, IBM, OmniNet, Sparkton Infotech,
How can we submit a form without a submit buttom?
12 Answers A1 Technology, IBM,
What are the uses of php language?
Write a program to find no of days between two dates in php?
Explain about switch statement in PHP?
How many ways to include variables in double-quoted strings in php?
Is array function in php?
Which function can be used to delete a file?
What is final class and final method in php?
code to see the priview of the image which is being uploaded (after browising the image... just click priview ... how it will be visible...before uploading)
What are the array functions in php?