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 10 of 11.
Animesh priyadarshi said:
1 decade ago
In object-oriented programming , a singleton class is a class that can have only one object (an instance of the class) at a time. For example, using Visual C++ , the "Application" class is an example of a singleton class. You can only create only one object of an Application class.
Manivannan said:
1 decade ago
What is a singleton class ?
Maha said:
1 decade ago
Difference between virtual and friend class ?
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.
Deepi said:
1 decade ago
What is the use of singleton class?
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;
}
}
};
Prasanth said:
1 decade ago
Write a simple exemples in Singleton class?
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.
Sneha said:
1 decade ago
How to make singleton class?
Rakesh Sharma said:
1 decade ago
Write the use of singleton class in a program in easy to understand language.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers