Place Ads here

Tuesday, June 21, 2011

Static Classes

Asp.Net sample projects


                                                                      Static Classes


  • Classes  that do not have or contain representative (instance) members and do not have a constructor that can be called as Static Classes.
  • Static Keyword is used for declaring Static Class.
  • No need to create objects so program execution is faster.
Example


Using System;
Namespace StaticProgram;
{
Class Program
{
Static void main (string[]args)
{
Demo.Display1();
Demo.Display2();


Static Class Demo
{
public static string sa;
static string sb;


public static void Display1()
{
sa="Amul";
console.writeline("{0}Says",sa);
console.writeline("I am in Static method Display1(),So I can be called by Class Representation.I don't require an Object Declaration");
}






public static void Display2()
{
sb="Amul";
console.writeline("{0}Says",sb);
console.writeline("I am also in Static method Display2(),So I can be called by Class Representation.I don't require an Object Declaration");
}
}

}
}

No comments:

Post a Comment