Описание тега extending-classes
Method extending, in object oriented programming, is a language feature that allows a subclass or child class to inherit all the methods and properties of the extended class.
You can extend a class to provide a more specialized behavior.
A class that extends another class inherits all the methods and properties of the extended class. In addition, the extending class can override the existing methods. Overriding a virtual method allows you to provide a different implementation for an existing method. This means that the behaviour of a particular method is different based on the object you're calling it on. This is referred to as polymorphism.
A class extends another class using the extends keyword in the class definition. A class can only extend one other class.
Example in PHP
class Hello {
public function message() {
return "Hello";
}
}
class HelloWorld extends Hello {
public function message() {
return parent::message() . " World";
}
}
$class = new HellowWord();
echo $class->message(); //"Hello World"
In this example we extend the class Hello
, and override the function message
.
Related tags: override method-overriding function-overriding