Explain Global variable

Global variable: It is a phenomenon which is more generally regarded as being a trouble in structured programming languages than in object-oriented languages. In structured programming language, like C or Pascal, a global variable is one stated outside the procedures and functions of a program. This is hard to keep track of the usage of this variable as it is readable and writable by the entire program or module in which it is stated. This makes these variables a general source of logical errors. However, instance variables pose a similar trouble within class definitions, as Java's scope rules make them available to all methods stated within a class. This is one of the reasons why we favor to channel access to instance variables via accessor and mutator techniques even in a class.

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.