Complete the code to declare an interface named Vehicle.
<?php
interface [1] {
public function start();
}
?>The keyword interface is followed by the interface name. Here, the interface is named Vehicle.
Complete the code to implement the Vehicle interface in the Car class.
<?php
interface Vehicle {
public function start();
}
class Car [1] Vehicle {
public function start() {
echo "Car started";
}
}
?>In PHP, a class implements an interface using the keyword implements.
Fix the error in the code by completing the method signature in the Car class.
<?php
interface Vehicle {
public function start();
}
class Car implements Vehicle {
public function [1] {
echo "Car started";
}
}
?>The method name must exactly match the interface method including parentheses. So it should be start().
Fill both blanks to declare an interface and a class that implements it with a method.
<?php interface [1] { public function [2](); } class Bike implements Vehicle { public function start() { echo "Bike started"; } } ?>
The interface is named Vehicle and the method declared is start(), matching the class implementation.
Fill all three blanks to create an interface with two methods and a class implementing both.
<?php interface [1] { public function [2](); public function [3](); } class Plane implements Flyable { public function takeOff() { echo "Plane taking off"; } public function land() { echo "Plane landing"; } } ?>
The interface is named Flyable and declares two methods: takeOff() and land(), which the class Plane implements.