What is a static class in C#?
Classes can be defined as user-defined data types representing an object’s state (properties) and behavior (actions).
Types of classes
There are four major types of classes in C#:
- Abstract class
- Partial class
- Sealed class
- Static class
Static class
It is a type of class similar to a sealed class but has a static data member, static constructor, and static method. One can generate a static class by using the static keyword.
A static class can not be inherited by another class, and we can not create its object.
Example
The following code will help understand the use of the static class:
using System;namespace ExampleOfStaticClass {// Creating static class// Using static keywordstatic class Circle {//static variable that contains the value of pipublic static double Pi = 3.14;//static method that takes the radius of the circle as parameter and returns the areapublic static double Area(double radius) {return Pi * radius * radius;}}// Driver Classclass Program {static void Main(string[] args) {double radius = 5;//calculating the area of the circle by calling the static method of Circle class without creating its objectdouble area = Circle.Area(radius);Console.WriteLine("Area of circle is: " + area);}}}
Explanation
- Line 7: We declare a class
Circleusing thestatickeyword. - Line 8: Declared a static variable
Pi. - Lines 13–14: Declared a method
Areathat will return the area of the circle. - Line 23: Calculate the circle area by calling the static method of
Circlewithout creating its object. - Line 24: Print the area of circle on the console.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved