Inheritance, Interfaces, and Exceptions Flashcards
You will use the keyword _____ to apply *inheritance* from a parent to a child class.
extends
What is the definition of inheritance?
Inheritance is a well-established programming principle, and PHP makes use of this principle in its object model. This principle will affect the way many classes and objects relate to one another.
How can I access the static method “getMaker()”?
static::getMaker();
What is the proper way to access a parent property named “price”?
parent::price
You use the keyword _____ to use an interface on an class.
implements
What are object inferfaces?
Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.
Code Challenge
class Trout extends Fish { public $species;
function \_\_construct($name, $flavor, $record, $species) { parent::\_\_construct($name, $flavor, $record); $this-\>species = $species; }
public function getInfo() {
$output = “{$this->species} {$this->common_name} tastes {$this->flavor}.”;
$output .= “The record ($this->species} {$this->common_name} weighed {$this->record_weight}.”;
return $output;
}
}
$brook\_trout = new Trout("Trout", "Delicious", "14 pounds 8 ounces", "Brook"); echo $brook\_trout-\>getInfo();