in case 4, when both the reference and instance are of C, can we not use super keyword to call the function of P class
Can we use super to call the function of parent
Super is used when we want to call parent class method.
So whenever a parent and child class have same named methods then to resolve ambiguity we use super keyword.
method_name(); will give me the method from child class.
super.method_name(); will give me the method from parent class
yes,but in the video she said that there is no way to call the method of the parent class if the instance and reference is made of the child class.
@apoorvsingh27,
super can be used only and only if the method names are same. You have to keep that in mind as well also.
the method name is same in both the parent and child class
yes, that is true when you are outside the class.
super always refer to the parent of the class where it is being used, like if you use super keyword from inside Client class, it will refer to the parent of Client class not P class. that’s why you can’t use super keyword from that context mentioned in the video to call parent method.
so to call any method of P class, you must use super keyword from inside C class. moreover super keyword can not be used from any static context as it is non static thing.
thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.