Class is not abstract and does not override abstract method

前端 未结 2 1724
既然无缘
既然无缘 2020-11-29 06:02

So I\'ve been working on a homework on abstraction for my programming class and fell into a problem. The goal for me right now is to be able to use abstraction, then later b

2条回答
  •  时光说笑
    2020-11-29 06:39

    If you're trying to take advantage of polymorphic behavior, you need to ensure that the methods visible to outside classes (that need polymorphism) have the same signature. That means they need to have the same name, number and order of parameters, as well as the parameter types.

    In your case, you might do better to have a generic draw() method, and rely on the subclasses (Rectangle, Ellipse) to implement the draw() method as what you had been thinking of as "drawEllipse" and "drawRectangle".

提交回复
热议问题