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.

Vedanti said:   9 years ago
@Kalaivani.

Singleton class is one whose only one instance (object) can be created. The object is declared globally so that we can use it anywhere in the program.

But this should be avoided as per the fundamental principles like encapsulation or data hiding. Singleton class can also be created by using all static methods which require no instance to call a method.

Eg:-

In the case of an atm machine when we insert our card, an instance is created for our account and all the transactions are created using that single instance of that card.

Kalaivani said:   9 years ago
Give more explanation for singleton class with clear example.

Raj said:   9 years ago
Singleton used in the development of an application like public chat, cricket score.

Bhargav said:   9 years ago
Can we use any other class, other than singleton class?

Shri said:   9 years ago
I too didn't understand this singleton class.

Raj said:   10 years ago
What is friend class? Explain?

Varsha said:   10 years ago
Please explain in this question in details.

Davis said:   10 years ago
Only single class can be inherited, no multiple inheritance can take place here.

Aparna said:   10 years ago
Singleton set is used for only one instance of the class.

Singleton means only one instance or object at a time can be created.

Singleton set example:

public class singleton();
{
private static singleton instance;
private singleton()
{

}

Public static singleton instance (this is one and only one way to obtain any instance of the singleton set).
{
get
{
if(instance==null)
{
instanece = new singleton(); (memory will be allocated only on first call to the 'instance' property)
}
return instance;
}
}

Hari Narayanan said:   1 decade ago
If it is singleton, explain others?


Post your comments here:

Your comments will be displayed after verification.