Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling super method from unrelated method

Today I realized that calling super.foo() is possible not only inside an overriding foo method, but also inside completely unrelated methods:

class Base
{
    void foo()
    {
    }
}

class Derived extends Base
{
    void foo()
    {
    }

    void bar()
    {
        super.foo();    
    }
}

Is there any real-world scenario, Design Pattern or whatever where this is actually useful?

like image 728
fredoverflow Avatar asked Apr 30 '26 00:04

fredoverflow


1 Answers

This would be helpful when a child class wants to provide more meaningful names to a method than the parent class, or providing additional information about the operation in the method name.

like image 196
Mohit Kanwar Avatar answered May 01 '26 13:05

Mohit Kanwar