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 5 of 11.

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.

Manish singh said:   1 decade ago
When class having only one class is called singleton class;

Means that single=means one it means that required of one object.

Kiran said:   1 decade ago
So the class derived as private is called singleton class?

Kamal dhaker said:   1 decade ago
How we create singleton class?

Sonu said:   1 decade ago
What is meant by singleton class?

Ananadan b said:   1 decade ago
How to make singleton class?

Shaju said:   1 decade ago
Making constructor as private it will not allow any other function even main to create an object. Only inside class, object can be created.

Shaju said:   1 decade ago
Singleton means only one instance or object at a time can be created.

Why using (for eg: only one person can open a mailbox from a system using a web browser from a system).

Rohit said:   1 decade ago
What is use of this mainly in c++?

Ramya said:   1 decade ago
I expect that friend, virtual class doesn't access more than one object.


Post your comments here:

Your comments will be displayed after verification.