adspace
Answer Posted / Ajay Kumar Kushwaha
In PHP, inheritance is a process where one class acquires the properties and methods of another. This is done by declaring a class as a subclass (child) of another class (parent). Here's an example:
```php
// Parent class
class Animal {
public $name;
function __construct($name) {
$this->name = $name;
}
function eat() {
echo $this->name . ' is eating.';
}
}
// Child class
class Dog extends Animal {
function bark() {
echo $this->name . ' is barking.';
}
}
$myDog = new Dog('Rex');
$myDog->eat(); // Rex is eating.
$myDog->bark(); // Rex is barking.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is trait in php?
What is the current stable version of php? What advance thing in php7?
Explain me is it possible to destroy a cookie?
List some features of php that are deprecated in php7?
What is the difference between htmlentities() and htmlspecialchars()?
sort term descripttion form, report and uery
Write a program using while loop?
How to calculate the difference between two dates using php?
What is difference between static and final in php?
Which variable declarations within a class is invalid in php?
hello all, I need some sample placement papers in lion bridge.. can anyone help me?
How to create a web form?
Name and explain five of the PHP error constants?
How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain
how to detect a mobile device using php