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

when ever the user logged in the database table the current registered date will be appeared

3 Answers  


Maine 12th ke bad 2 years ka web designing ka course kiya hai. Php me achcha hu. Ek fresher ko is field me kitna mil sakta hai ?

0 Answers   TCS,


What is the purpose of the php empty function?

0 Answers  


Which is best framework for php?

0 Answers  


How do you explain independent and dependent variables?

0 Answers  


What is meant by pdo in php?

0 Answers  


What is the php function that removes the first element of the array and returns it?

0 Answers  


Tell me how do you define a constant?

0 Answers  


What is the importance of "action" attribute in a html form?

0 Answers  


Explain different types of errors in PHP (i.e. arguments in errorreporting function)?

8 Answers   Base2 Infotech, DCI, Microsoft, Tata Elxsi,


Explain mysql_error().

0 Answers  


how to make website package setup like desktop software setup ... that front end and backend can include in setup like single package...?

0 Answers  


Categories