Ace Your C++ Skills 2025 – Rock the ‘Thinking in C++’ Challenge!

Question: 1 / 565

How can a class ensure it only has one instance?

By making its constructor private

Using the 'singleton' pattern with a static member of the same class type

The 'singleton' pattern is a design pattern that ensures a class only has one instance while also providing a global point of access to that instance. Option A is incorrect because making the constructor private doesn't prevent multiple instances from being created, it just prevents outside classes from creating instances. Option C is incorrect because declaring all methods as static doesn't prevent multiple instances from being created without the use of the 'singleton' pattern. Option D is incorrect because making the class abstract doesn't ensure only one instance can be created.

Get further explanation with Examzify DeepDiveBeta

Declaring all its methods as static

By making the class abstract

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy