Disabling inherited method on derived class

后端 未结 10 1721
野趣味
野趣味 2020-12-03 06:59

Is there any way to, in a Java derived class, \"disable\" a method and/or field that is otherwise inherited from a base class?

For example, say you have a Shap

10条回答
  •  北海茫月
    2020-12-03 07:09

    You can override the specific method "rotate()" in the class you want to disable this operation, like this

    public void rotate() {
        throw new UnsupportedOperationException();
    }
    

提交回复
热议问题