Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is a controller in programming?

1060


Hello Friends,I am seeking for a job in php having 9 months. exp.Please suggest any company openings.

2125


How do I end a php session?

945


Which is better wamp or xampp?

972


Why do we use in php?

990


How escape single quotes php?

977


What is __ construct in php?

997


What is a base url?

931


How do I get csrf token?

968


What is the difference between echo print and print_r in php?

1001


What does $_env means?

936


Explain the difference b/w static and dynamic websites?

1019


What is cakephp framework?

1067


What do you mean range() in php?

1094


What are php variables?

979