Reputation: 357
Is their any way to prevent function overriding of a super class in subclass. if yes please let me know. thanks in advance.
Upvotes: 0
Views: 35
Reputation: 40730
You can use the final
keyword:
Examples:
class CanBeInherited {
public final function cantBeInherited() {
...
}
}
final class CannotBeInherited {
public function cantBeInheritedEither() {
...
}
}
class Child extends CanBeInherited { } //This is fine
class Child2 extends CanBeInherited {
public function cantBeInherited() {} //Error
}
class Child3 extends CannotBeInherited {} //Error
Upvotes: 1
Reputation: 455
declare function in this way in super class
class Foo
{
final public function bar()
{
//Do action A
}
}
Upvotes: 1