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

How do you convert boolean to boolean?

527


When do I need to use reflection feature in java?

627


Is arraylist dynamic in java?

525


What are multiple inheritances? Is it supported by java?

469


Can a class have more than one object?

532






What is array size in java?

501


What do you mean by hashing?

647


Is java programming easy?

545


What is local class in java?

524


how do I create a runnable with inheritance? : Java thread

509


What do you mean by platform independence? What is an interface?

570


What is instance means in java?

566


What is the purpose of object oriented programming?

540


Tell us something about different types of casting?

523


How the metacharacters are different from the ordinary characters?

571