Header Ads

  • Breaking Now

    What is the difference between class variable, member variable and automatic(local) variable?

    The class variable is a static variable and it does not belong to any instance of class but shared across all the instances.
    The member variable belongs to a particular instance of class and can be called from any method of the class.
    The automatic or local variable is created on a method entry and valid within method scope and they have to be initialized explicitly.


    3 comments:

    1. A member variable cannot be called from a static method.

      ReplyDelete
    2. If a member var is static then it should be..

      ReplyDelete
    3. If a variable is static in the class, it isn't named as 'member' variable, it is a 'class' variable.

      Therefore member variables cannot be static. They are members of an instance.

      ReplyDelete

    Post Top Ad

    Post Bottom Ad