Sobes.tech
Junior — Middle

Can an abstract class include private methods?

sobes.tech AI

Answer from AI

Yes, an abstract class in PHP can contain private methods. Private methods are only accessible within the class itself and are not visible to subclasses. This is useful for encapsulating auxiliary logic that should not be overridden or accessible from outside. For example:

abstract class BaseClass {
    private function helper() {
        // private logic
    }
    abstract protected function doWork();
}

Thus, an abstract class can have both abstract methods to be implemented in subclasses and private methods for internal use.