Explain about global variables in Java?

Answer Posted / satish

Direct global variables are not possible like

int i=0;
class{
....
....
}

But other way is create a class with static variables and
you can use it wherever needed.

class Global{
public static int i;
public static String s="";
}

class SomeClass{
public static void main(String args[]){
Global.i=23;
Global.s="Whats up"
}
}

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is java reflection?

775


How to create a custom exception?

768


What about interrupt() method of thread class ?

858


What defines function?

754


What does the “static” keyword mean?

844


Which package is used for pattern matching with regular expressions?

876


Explain the difference between the public, private, final, protected, and default modifiers?

814


Write an algorithm for quick sort?

825


How do you compare characters in java?

746


Can this keyword be used to refer static members?

814


What is an immutable class?

864


What is static data type in java?

793


What is indexof?

742


Why main() method is public, static and void in java ?

858


What does flagged out mean?

821