Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-04-2009
Member
 
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
Reply With Quote
  #2  
Old 25-04-2009
Member
 
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.
Reply With Quote
  #3  
Old 25-04-2009
Member
 
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
Reply With Quote
  #4  
Old 25-04-2009
Member
 
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).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is Global Variable static? Declaring static variable instead of Global variable"
Thread Thread Starter Forum Replies Last Post
Servlet static variable Sheenas Software Development 5 06-03-2010 11:24 AM
Static variable initialization Dilbert Software Development 3 31-12-2009 01:38 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM
Is it possible to have static variable in python? gvBlake Software Development 2 21-07-2009 09:56 PM
Can we use static variable in other programming languages FlayoFish Software Development 2 25-04-2009 10:56 AM


All times are GMT +5.5. The time now is 08:09 PM.