Does Java have global variables?

Why there are no global variables in java?

  • Please answer my question in detail..

  • Answer:

    You have asked this question in wrong section. You must go to the Computers & Internet Section > Programming and Design. There you can find your answer. ---------------------------------------… However, I am answering your question. I Hope you would get it. Global variables do not live well with OOP. Still one can have constants as global variables If you really want to declare global variable, make it a public static variable A simple way to utilize "global" variables in Java is to define a class Global with the desired variables as static members of it: public class Global { public static int x = 37; public static String s = "aaa"; } Such members can be accessed by saying: public class test { public static void main(String args[]) { Global.x = Global.x + 100; Global.s = "bbb"; } } =======================================…

Cutie at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

variables....................... ip ............................... 12th ........................... exam ..................... tenson .......................... cry ........................................…

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.