英文:
why enum has constructor when interface cant have one?
问题
已知接口不需要构造函数,因为接口的所有数据成员都是public、static和final的。同样,枚举也将其所有常量都声明为public、static和final,那么它为什么需要/有构造函数?
英文:
It is known that Interface doesn't need constructor because all the data members of interface are public,static and final. Similarly enum also has all its constants as public static and final then how come it needs/had a constructor?
答案1
得分: 5
An interface cannot be instantiated, an enum can (and in fact will be, as each of its members is an instance of the enum itself).
英文:
An interface cannot be instantiated, an enum can (and in fact will be, as each of its members is an instance of the enum itself).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论