Implement a final class without the “final” keyword

后端 未结 7 1622
生来不讨喜
生来不讨喜 2020-12-29 10:53

A friend of mine was asked that question in his on-phone job interview a couple of days a go. I don\'t have a clue. can anyone suggest a solution? (His job interview is ov

相关标签:
7条回答
  • 2020-12-29 11:20

    I don't know what they mean exactly mean by a final class. If they mean a class that cannot be extended by inheritence, than clearly this cannot be done, except by marking that class with final (or sealed, or whatever the language keyword is).

    But if the mean final as in immutable, such that a derived class can't modify the value of the fields in the class,than the base class should have all of the fileds and accessor methods private.

    0 讨论(0)
提交回复
热议问题