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 difference between session and cookies in php?

0 Answers  


List types of array are available in php?

0 Answers  


What is the difference between laravel and php?

0 Answers  


Tell me how to find the length of a string?

0 Answers  


Is session a cookie?

0 Answers  






In how many ways we can retrieve the date in the result set of mysql using PHP?

5 Answers   Yahoo,


Explain converting an object?

0 Answers  


What is the difference between query and question?

0 Answers  


What are the advantages of indexes?

0 Answers  


Write a php function to convert all null values to blank?

0 Answers  


What is compact function php?

0 Answers  


Is php used anymore?

0 Answers  


Categories