Multiple choice technology programming languages

What is singleton class?

  1. that can not be inherited

  2. that can be inherited only once

  3. that can have only one object

  4. there is no such class

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A singleton class is a design pattern that restricts instantiation of a class to one object. This is achieved by making the constructor private, declaring a static instance variable, and providing a static public method (usually getInstance()) that returns the instance. Option C correctly states that a singleton can have only one object. Options A and B describe inheritance restrictions, which are not the definition of singleton.

AI explanation

A singleton class is a design pattern where the class is written so that only one instance of it can ever exist in the application, typically enforced with a private constructor and a static accessor method that returns the same shared instance every time.