What is an abstract class in PHP?
An abstract class is a class that contains at least one abstract method. An abstract method is a method that is declared, but not implemented in the code.
An abstract class or method is defined using the abstract keyword.
PHP has abstract classes and methods. Classes defined as abstract cannot be instantiated, and any class that contains at least one abstract method must also be abstract.
Abstract Methods declare the method's signature but they cannot define any implementation or body parts.
All abstract methods of Abstract class must be implemented in its child class.
An abstract class also contains Common method (with implementation or body parts)
Child Class must be declared as abstract or implement the remaining abstract methods of abstract class.
PHP Syntax:
<?php
abstract class SuperClass {
abstract public function Method1();
abstract public function Method2($param1, $param2);
// Common method
public function Display() {
//code to be executed.
}
}
class ChildClass extends SuperClass
{
//class methods
}
?>
Comments