Static member is a member that belongs to the class and not to the objects of the class. Static members are specified using the keyword static. The three valid static members of a class are static constructor, static variable and static method.
Static Variables:
When a variable or attribute of a class is declared as static then it is called as Static Variable. Only one copy of static variable will be stored in the memory. All the objects of the class will be accessing the same copy of it.
Static Methods:
Static methods are the methods which are marked as static. Static method can access only static members of a class. Static methods cannot access non-static or instance members of a class.
Static Constructors:
Static constructors are special type of constructors that are called when the class is loaded for the first time. Static constructors are used to initialize static variables of a class.
Static Variables:
When a variable or attribute of a class is declared as static then it is called as Static Variable. Only one copy of static variable will be stored in the memory. All the objects of the class will be accessing the same copy of it.
Static Methods:
Static methods are the methods which are marked as static. Static method can access only static members of a class. Static methods cannot access non-static or instance members of a class.
Static Constructors:
Static constructors are special type of constructors that are called when the class is loaded for the first time. Static constructors are used to initialize static variables of a class.
Comments
Post a Comment