0
0
PHPprogramming~10 mins

Abstract classes and methods in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an abstract class named Vehicle.

PHP
<?php
abstract class [1] {
}
?>
Drag options to blanks, or click blank then click option'
AVehicle
Bvehicle
Cabstract
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'vehicle' instead of 'Vehicle'.
Writing 'abstract' as the class name.
Omitting the class name.
2fill in blank
medium

Complete the code to declare an abstract method named startEngine inside the abstract class.

PHP
<?php
abstract class Vehicle {
    public abstract function [1]();
}
?>
Drag options to blanks, or click blank then click option'
Astartengine
Bstart_engine
CStartEngine
DstartEngine
Attempts:
3 left
💡 Hint
Common Mistakes
Using all lowercase or underscores in the method name.
Capitalizing the first letter incorrectly.
3fill in blank
hard

Fix the error in the code by completing the method declaration correctly.

PHP
<?php
abstract class Vehicle {
    public abstract function [1]();
}
?>
Drag options to blanks, or click blank then click option'
AstartEngine
Babstract startEngine
Cabstract function startEngine
DstartEngine()
Attempts:
3 left
💡 Hint
Common Mistakes
Including keywords like 'abstract' or 'function' in the blank.
Adding parentheses in the blank.
4fill in blank
hard

Fill both blanks to complete the class that extends the abstract class and implements the abstract method.

PHP
<?php
class Car extends [1] {
    public function [2]() {
        echo "Engine started";
    }
}
?>
Drag options to blanks, or click blank then click option'
AVehicle
BstartEngine
Cstartengine
Dvehicle
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'vehicle' instead of 'Vehicle'.
Incorrect method name casing.
5fill in blank
hard

Fill all three blanks to create an instance of the class and call the implemented method.

PHP
<?php
$car = new [1]();
$car->[2]();
echo $car instanceof [3] ? "Yes" : "No";
?>
Drag options to blanks, or click blank then click option'
ACar
BstartEngine
CVehicle
Dcar
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase class names.
Calling a method that does not exist.
Checking instance against wrong class.