Static Members

  §  Static local variables
  §  Static member variables
  §  Static member functions

Static Local Variables

  §  Concept as it is taken from C.
  §  They are by default initialized to Zero.
  §  Their lifetime is throughout the Program.
   
   e.g

#include<iostream.h>
#include<conio.h>

void fun()

{
     static int x;
     int y;
}

https://abhisharmaofficial.blogspot.com/

Static member variables

  §  Declared inside the class body.

  §  Also known as class member variable

  §  They must be defined outside the class.

  §  Static member variables does not belong to any object, but to the whole class.

  §  There will be only one copy of the static member variable for the whole class.

  §  Any object can use the same copy of the class variable

  §  They can also be used with class name.


#include<iostream.h>
#include<conio.h>
class account
{
Private :
    int balance ;    // instance member variable
    static float roi;   // Static member variable
Public :
    void setbalance( int b)
     {
         balance = b;
      }
} ;
float account :: roi = 3.15;
void main()
{
   Clrscr();
   account a1;
}

  §  a1 object has does not have the roi variable but have balance variable. 

https://abhisharmaofficial.blogspot.com/

**You reached end of lecture**