Skip to content
Justice Tech School

Interfaces

An interface lists methods a class must write. A class can implement several.

Example
interface Shape { function area(): float; }
class Sq implements Shape { function __construct(private float $s) {} function area(): float { return $this->s ** 2; } }
echo (new Sq(3))->area();

Result

9

Exercise

Use an interface.

class A  I {}

Quiz Test

Can a class implement many interfaces?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.