- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to prove that only one instance of the object is created for static class?
Here in the example a static Demo class is created and a static variable count is declared.
Here the count variable is treated as a global variable .so it keeps on increasing in the example ,because only one instance of the class is created
Example
static class Demo{ public static int count; static Demo(){ System.Console.WriteLine("Static Constuctor called"); } } class Program{ static void Main(){ Demo.count++; Demo.count++; System.Console.WriteLine(Demo.count); Console.ReadKey(); } }
Output
Static Constuctor called 2
Advertisements