Static Class:
A Static Class is one which cannot be instantiated. The keyword new cannot be used with static classes as members of such class can be called directly by using the class name itself.
Following are the main characteristics of a static class:-
• A Static Class can only have static members.
• A Static Class cannot be instantiated.
• A Static Class is sealed, so cannot be inherited.
• A Static Class cannot have a constructor (except static constructor).
Static Class is denoted by the keyword static.
Example:
// static class
definition…
public static class myclass
{
public static int
addNumbers(int a, int
b)
{
return
(a + b);
}
}
// to use it, we call directly on the class… Console.WriteLine("The addition of 5 and 7 is: " + myClass.addNumbers(5, 7));
0 comments:
Post a Comment