While static fields and methods in Java and C# have the same function and meaning, static classes are different.
In C#, a static class may contain only static members, and cannot be instantiated into an object. It is also sealed - another class cannot inherit from it.
In Java, a static class is called a static member class. It must be declared inside another class. It is actually a regular class - it has none of the restrictions mentioned above for C# static classes. It is similar to a regular nested class in C#. So what's "static" about it? It can only reference static members of its containing class. This is in contradiction to a Java nonstatic member class, which automatically holds a reference to its containing class via the "this" keyword.
In Java, to make a static class behave more like a C# static class (namely to prevent its instantiation into an object), make its constructor private.
The writer is R&D team leader at Niloosoft Hunter HRMS
The writer is R&D team leader at Niloosoft Hunter HRMS
Thank you so much!
ReplyDeleteNice one. Thanks.
ReplyDeleteNice article.you have explained static in java very well. Keep this job up. there is also good static in java tutorial visit Static in Java
ReplyDelete