Complete the code to type hint the parameter as the parent class.
<?php class Animal {} function feed([1] $animal) { echo "Feeding animal"; } ?>
The parameter should be type hinted as the parent class Animal to accept any subclass instance.
Complete the method signature to accept any subclass of Vehicle using type hinting.
<?php class Vehicle {} class Car extends Vehicle {} function startEngine([1] $vehicle) { echo "Engine started"; } ?>
The method should accept the parent class Vehicle to allow any subclass like Car.
Fix the error by correctly type hinting the parameter to accept any subclass of Fruit.
<?php class Fruit {} class Apple extends Fruit {} function eat([1] $fruit) { echo "Eating fruit"; } ?>
Type hinting with the parent class Fruit allows the function to accept any subclass like Apple.
Fill both blanks to create a function that accepts any subclass of Device and calls its method.
<?php class Device { public function powerOn() { echo "Device powered on"; } } class Phone extends Device {} function activate([1] $device) { $device->[2](); } ?>
The parameter should be type hinted as Device to accept any subclass. The method called is powerOn defined in the parent class.
Fill all three blanks to define a function that accepts any subclass of Employee, checks the role, and prints a message.
<?php class Employee { public function getRole() { return "Employee"; } } class Manager extends Employee { public function getRole() { return "Manager"; } } function printRole([1] $emp) { if ($emp->getRole() === [2]) { echo [3]; } } ?>
The function parameter is type hinted as Employee to accept any subclass. It compares the role string to "Manager" and prints the message "Manager role detected".