Attributes / member variables in interfaces?

前端 未结 7 1444
眼角桃花
眼角桃花 2020-12-04 14:09

I wish to know is there any way in which I can make it compulsory for the implementer class to declare the objects handles/primitives as they do with methods. for e.g.:

7条回答
  •  鱼传尺愫
    2020-12-04 14:46

    You can only do this with an abstract class, not with an interface.

    Declare Rectangle as an abstract class instead of an interface and declare the methods that must be implemented by the sub-class as public abstract. Then class Tile extends class Rectangle and must implement the abstract methods from Rectangle.

提交回复
热议问题