How would you design a class that shouldn’t be instantiated?
- By declaring the class as abstract.
- By defining a private constructor.
- By making the class private.
- By using the final keyword.
To prevent a class from being instantiated, you can define a private constructor. When the constructor is private, it cannot be called from outside the class, effectively preventing object creation.
Loading...
Related Quiz
- In a project where memory efficiency and speed are of utmost priority and the data doesn't need any modification once set, which data structure would be a better choice?
- A ____ in Python is a collection of key-value pairs, where the keys must be immutable.
- You are assigned to implement a complex object creation scenario where the object’s construction process should be separate from its representation. Which design pattern would you use?
- The ____ function in Python’s time module can be used to measure the elapsed time and is useful for profiling.
- Which Python library is typically used for parsing and generating JSON data?