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

Does printwriter create a file?

626


What is a boolean structure?

655


Can we overload run() method in java?

695


What is bufferedreader in java?

684


What is the association?

653






How many times finalize method will be invoked? Who invokes finalize() method in java?

671


Give an example of call be reference significance.

697


What are scalar data types?

603


How to split a string in java?

732


What is length in java?

668


How to perform binary search in java?

671


What is boolean keyword in java?

727


What is a loop java?

664


Why do we use return statement?

627


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

688