C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 1)
1.
Which of the following type of class allows only one object of it to be created?
Virtual class
Abstract class
Singleton class
Friend class
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
104 comments Page 3 of 11.

V.sriram said:   1 decade ago
I can't understand concept of singleton class? let you to explain?

Priyanka said:   1 decade ago
I can't understand concept of singleton class? please explain with example.

Vai said:   1 decade ago
Whenever we a class gets loaded only one single class class object gets created for that class which is singleton for that particular class.

Kanika said:   1 decade ago
I don't know about singleton class..
and shouldn't it be protected class????

Dattatraya dhokane said:   1 decade ago
Can I get more info about singltone class.

Uma said:   1 decade ago
A class which is having only single object is called singleton.

Chandrababu said:   1 decade ago
What is the use of singleton class? please give me simple explanation.

Bibhishan said:   1 decade ago
Singleton class has only one instance this concept given in the design pattern.

Lalit Kumar Soni said:   1 decade ago
I can't understand following statement:

static A* m_objA;

And Also term Singleton & Longer class.

LoveToProgram said:   1 decade ago
A Singleton class is a design pattern, which creates only a single instance at any time.

When is it required:

Based on the requirement.

Example : Singletons are often used to control access to resources such as database connections or sockets.

Suppose u have licence for only one connection for database, A singleton connection obj makes sure that only one connection can be made at any time.

How this can be implemented:

1. Have a static method, creates the instance if the instance does not exists. If the instance already there then returns the reference to the existing obj.

2. Have a private constructor.

Why Static method:

No obj is required to call static method and memory is used only when required.

private constructor is to make sure that object is not created in any other way.

I explained as per my knowledge. Hope this would be useful.


Post your comments here:

Your comments will be displayed after verification.