September 21, 2008

static in java and c#


Java:
In java if you don't wanna create an instance of a class. Simply put a private constructor in that class.

C#
In C# also u can follow the same approach but the .net platform provides a simple feature called static class.Look at the following code:

static class MyClass
{
static void hello()
{
Console.WriteLine("Hello World");
}
}
This class can only contain static data.

Note: You can't find static classes in java

0 comments: