创建一个类的对象 [英] creating a object of class
本文介绍了创建一个类的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何防止在没有其抽象类,静态类和私有构造函数的情况下创建类的对象.
how to prevent to creating a object of class without its make abstract class,static class,and private constructor.
推荐答案
我只能看到另一种方法要做到这一点,那就是一种病态的:以总是抛出异常的方式定义所有(非私有)构造函数.
我只想告诉这个问题,这是一个廉价的练习.它类似于一些想发明的毫无意义的面试问题之一.我认为,这与真实知识无关.我很乐意与无法正确回答这个问题,但能对事物有深刻思考和真正理解的人一起工作.
—SA
I can see just one more way to achieve that, a pathological one: define all (non-private) constructors the way they always throw an exception.
I just want to tell that this question is a cheap exercise. It resembles one of those pointless interview questions some like to invent. In my opinion, it has little to do with real knowledge. I would happily work with someone who would not be able to answer this question correctly but show some deep thinking and real understanding of things.
—SA
这篇关于创建一个类的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文