Inheritance, Interfaces, and Exceptions Flashcards

1
Q

You will use the keyword _____ to apply *inheritance* from a parent to a child class.

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the definition of inheritance?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can I access the static method “getMaker()”?

A

static::getMaker();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the proper way to access a parent property named “price”?

A

parent::price

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You use the keyword _____ to use an interface on an class.

A

implements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are object inferfaces?

A

Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Code Challenge

A
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();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly