Results 1 to 4 of 4

Thread: What is Global Variable static? Declaring static variable instead of Global variable

  1. #1
    Join Date
    Apr 2009
    Posts
    65

    What is Global Variable static? Declaring static variable instead of Global variable

    Hello,

    What is Global variable static? I have heard about the Global variable,does static variable different than Global variable, and what effect it will reflect if I replace Global static variable with the Global variable.
    I think there would be very little difference between them, please suggest some points related to this.

    Thanks

  2. #2
    Join Date
    Jan 2009
    Posts
    99

    Re: What is Global Variable static? Declaring static variable instead of Global variable

    Following is the Use of declaring a global variable static

    static prevents the variable from having external linkage.
    In C, variables have scope and linkage, neither of which is called "global."


    A static variable (for instance, a singleton) is a common Java way of achieving this. I have found however, that a more elegant way in Android is to associate your state with the Application context.

    As you know, each Activity is also a Context, which is information about its execution environment in the broadest sense. Your application also has a context, and Android guarantees that it will exist as a single instance across your application.

  3. #3
    Join Date
    Apr 2008
    Posts
    193

    Re: What is Global Variable static? Declaring static variable instead of Global variable

    Static remains throughout the program, however its scope is limited to that file alone. If a program consists of multiple files, you want a variable to be seen by the entire file and do not want that variable to be seen by the other files, then mark is as static.

    static int a;

    as a global variable

  4. #4
    Join Date
    Dec 2008
    Posts
    161

    Re: What is Global Variable static? Declaring static variable instead of Global variable

    A static global variable is a single variable and a private member of a class has a separate instance for every instance of the class. And using static global vars is definitely not OOP (besides the fact that anyone can modify it if he/she has access to it).

Similar Threads

  1. Servlet static variable
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 11:24 AM
  2. Static variable initialization
    By Dilbert in forum Software Development
    Replies: 3
    Last Post: 31-12-2009, 01:38 PM
  3. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  4. Is it possible to have static variable in python?
    By gvBlake in forum Software Development
    Replies: 2
    Last Post: 21-07-2009, 09:56 PM
  5. Can we use static variable in other programming languages
    By FlayoFish in forum Software Development
    Replies: 2
    Last Post: 25-04-2009, 10:56 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,492,345.02825 seconds with 17 queries