Can a constructor be private in Java?
- No, constructors can only be package-private
- No, constructors must always be public.
- Yes, constructors can be private in Java.
- Yes, constructors can only be protected.
Yes, constructors can be private in Java. A private constructor is often used in design patterns like Singleton to ensure that only one instance of a class can be created. It restricts external instantiation of the class.
Loading...
Related Quiz
- Which of the following statements about the 'this' keyword is incorrect?
- The ________ interface of the JDBC API provides cursor support, which allows forward and backward navigation through the result set.
- How can SQL Injection be prevented when executing queries using JDBC?
- How does the use of synchronized methods or blocks affect the performance of a Java application and why?
- What will be the output of the following code snippet: System.out.println("2" + 3);?