Can't declare an abstract method private

前端 未结 6 1608
再見小時候
再見小時候 2020-12-11 00:31

I want to do this, yet I can\'t. Here is my scenario and rational. I have an abstract class for test cases that has an abstract method called test(). The test() method is to

6条回答
  •  猫巷女王i
    2020-12-11 01:14

    Private methods are not polymorphic (you cannot inherit them), so it makes no sense to make a private method abstract. Making a method abstract means you'd have to override and implement it in a subclass, but since you can't override private methods, you can't make them abstract either.

    You should make it protected instead of private.

    Private really means private to the class you've defined the method in; even subclasses don't see private methods.

提交回复
热议问题