What is inheritance in php progaming?



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

Post New Answer

More PHP Interview Questions

What is php and its uses?

0 Answers  


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?

0 Answers  


Write a program to find no of days between two dates in php?

0 Answers  






Explain about switch statement in PHP?

0 Answers  


How many ways to include variables in double-quoted strings in php?

0 Answers  


Is array function in php?

0 Answers  


Which function can be used to delete a file?

0 Answers  


What is final class and final method in php?

0 Answers  


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)

0 Answers   Satyam,


What are the array functions in php?

0 Answers  


Categories