A private constructor prevents the class from being instantiated outside of the class and is commonly used in ________.
- Abstraction
- Inheritance
- Polymorphism
- Singleton Pattern
A private constructor is commonly used in the Singleton design pattern. The Singleton pattern ensures that a class has only one instance, and the private constructor prevents external instantiation. It is not typically used for inheritance, polymorphism, or abstraction.
Loading...
Related Quiz
- In a switch case, the ________ keyword is used to specify the code that should be executed if no case matches.
- The ________ method of the Thread class is used to determine if a thread is still running.
- You are given the task to refactor a long series of if-else-if conditions that check for various states of an object. The code is hard to read and maintain. What would be an efficient way to refactor this using modern Java features?
- The ______ method of the Lock interface is used to acquire the lock.
- What is the default value of a local variable of data type boolean in Java?