Can you extend a Final defined class?
Can you extend a Final defined class?
No, you cannot extend a class that has been defined as final
in PHP. The final
keyword is used to prevent a class or method from being overridden by child classes or subclasses.
When a class is marked as final
, it means that it cannot be inherited from, and no other class can extend it. Attempting to extend a final
class will result in a fatal error.
Here's an example:
final class FinalClass {
// class definition
}
class ChildClass extends FinalClass {
// this will result in a fatal error
}
In this example, FinalClass
is marked as final
, so attempting to create a child class ChildClass
that extends FinalClass
will cause a fatal error.
The final
keywo...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào