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?
Discussion:
104 comments Page 2 of 11.
Sanjaya said:
1 decade ago
class A
{
private:
static A* m_objA;
A(){}; //note constructor is private
public:
~A();
A* GetInstance()
{
if(m_objA)
{
return m_objA;
}
else
{
m_objA = new A();
return m_objA;
}
}
};
{
private:
static A* m_objA;
A(){}; //note constructor is private
public:
~A();
A* GetInstance()
{
if(m_objA)
{
return m_objA;
}
else
{
m_objA = new A();
return m_objA;
}
}
};
Susi said:
1 decade ago
Tell me also what is singleton class ?
Difference between virtual and friend class ?
How to make singleton class ?
I can't get your definition. Can you make me understand easier ?
Difference between virtual and friend class ?
How to make singleton class ?
I can't get your definition. Can you make me understand easier ?
Shivam Mishra said:
7 years ago
The Singleton class exactly means is that, if we create many objects in a class then it will point to the first object which has been created.
It will not point to other objects.
It will not point to other objects.
(6)
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).
Why using (for eg: only one person can open a mailbox from a system using a web browser from a system).
Rajkiran said:
1 decade ago
A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.
T.srinivas said:
1 decade ago
Above example in that one getInstance word used what is mean by GetInstance and A*GetInstance how it come nd wts mean by A*GetInstance please anybody Explain clearly?
Sudhir said:
1 decade ago
To answer in simple words, singleton class is the one having only one instance of it created. This is the condition to be satisfied by a class to be singleton.
Animesh priyadarshi said:
1 decade ago
@ nithya if in a class we don't want more than one object then we can choose singleton class..its purpose is to create only one object at a time
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers