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 |
What is difference between session and cookies in php?
List types of array are available in php?
What is the difference between laravel and php?
Tell me how to find the length of a string?
Is session a cookie?
In how many ways we can retrieve the date in the result set of mysql using PHP?
Explain converting an object?
What is the difference between query and question?
What are the advantages of indexes?
Write a php function to convert all null values to blank?
What is compact function php?
Is php used anymore?