What is inheritance in php progaming?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How to read one character from a file?

538


What is the difference between $name and $$name?

523


What is a simple php method to make a cross domain data request?

522


Suppose your zend engine supports the mode Then how can you configure your php zend engine to support Mode ?

569


Explain how is it possible to set an infinite execution time for php script?

505






What is default session time in php?

518


What is the purpose of $_ session?

514


What is the difference between myisam and innodb?

507


What is csrf token and how it works?

521


How to create a session? How to set a value in session?

517


Can we use get instead of post?

494


Explain the casts allowed in PHP?

583


What are include() and require() functions?

515


How to execute an sql query?

513


What is env in laravel?

537