What are static members of a class

When you create a class you can add two type of members to the class

  1. Instance members or non static members
  2. Static members

Instance members are those members who life span is related to the life span of the object. They get created in memory when the object gets created and they die when the object is removed from the memory.

Static members are those members whose life span is related to the life span of your program. They get created in memory when the program starts and they live in the memory till your program runs. Their life span is not affected by the creation or destruction of objects.

How to create static members in a class

In order to create static members in a class just add the keyword static in front of the data member or function and it will become static. For example look at the code below

class Test  {      public Int x, y;      public static int a, b;            public void Fun1()      {      }        public static void Fun2()      {      }  }

In the above code x and y are non static data members of the Test class whereas a and b are static members of the Test class. Similarly Fun1 is a non static function whereas Fun2 is a static function of the Test class.

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp