Force super class to not call overloaded methods of the subclass

조회 수: 6 (최근 30일)
Naum Derzhi
Naum Derzhi 2021년 5월 5일
댓글: Naum Derzhi 2021년 6월 25일
I have a base class and subclass inheriting from it. Base class has method A. Subclass overloads that method. I want to force the base class to use (only in some places) it's own method, not the one overloaded by subclass. Is there any way to do it?
Thank you

답변 (1개)

Shraddha Jain
Shraddha Jain 2021년 6월 22일
Hi Naum,
When you create an object obj of a superclass and then use obj to call the overloaded (or any) method of the superclass, the method defined in the superclass is called and not the one of the subclass.
Refer to this documentation for more information.
  댓글 수: 1
Naum Derzhi
Naum Derzhi 2021년 6월 25일
Hello Shraddha,
Sorry, but this does not help. What I want to happen is this: when super class has funcitons F1 and F2, and F2 calls F1, I want that F2 would call F1 of the SuperClass, not of the SubClass - in certain circumstances, when I tell it so.
Please, see the attached example classes. Both in SubClass and SuperClass the method F2 calls the method F1. In the subclass these methods first call the corresponding method of the SuperClass, which is the usual practice.
And this is what happens: when SubClass.F2 calls the SuperClass F2, the latter calls F1 of the SubClass. I want it to call F1 of the SuperClass. Maybe not always, but only when I want exactly this behavior. This is simple in C++. How can it be done in Matlab?
Thanks,
Naum

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Battery Pack Modeling에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by