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

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

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

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

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.

Prema said:   9 years ago
Define singleton class?

Rahul Thete said:   9 years ago
The Singleton's purpose is to control object creation, limiting the number of obejcts to one only. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. Singletons often control access to resources such as database connections or sockets.

For example, if you have a license for only one connection for your database or your JDBC driver has trouble with multithreading, the Singleton makes sure that only one connection is made or that only one thread can access the connection at a time.

S.jayachitra said:   9 years ago
What is the different between the singleton class and virtual class?

Rajeev said:   9 years ago
Why virtual class not access through any class?

Shantanu said:   9 years ago
Not getting the meaning of Singleton. Please describe it clearly.

Anni said:   9 years ago
What is an abstract class?

Describe it.


Post your comments here:

Your comments will be displayed after verification.