フィルターのクリア

How to avoid running superclass constructor?

11 ビュー (過去 30 日間)
Sanjeev Bashyal
Sanjeev Bashyal 2020 年 8 月 19 日
コメント済み: Sanjeev Bashyal 2020 年 8 月 23 日
You have defined a class derived from a parent class with a constructor. There is a constructor in the derived class. MATLAB implicitly runs the constructor of parent class and I do not want in my case. How can I avoid MATLAB implict superclass constructor call? Help me out.

採用された回答

Steven Lord
Steven Lord 2020 年 8 月 19 日
You cannot avoid the superclass constructor being called (explicitly or implicitly) from the subclass constructor. From the documentation: "If you do not make an explicit call to a superclass constructor from the subclass constructor, MATLAB makes the implicit call when accessing the object."
If you don't want your subclass constructor to call the superclass constructor, are you sure that you want the subclass to inherit from the superclass?
  3 件のコメント
Steven Lord
Steven Lord 2020 年 8 月 23 日
Can you explain in more detail what your superclass and subclass represent? It's possible that inheritance is not the right tool for your class hierarchy.
If you want something that walks like a duck, quacks like a duck, and swims like a duck but isn't a duck, it shouldn't inherit from the duck class.
Sanjeev Bashyal
Sanjeev Bashyal 2020 年 8 月 23 日
Thanks a lot, I got you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by