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

Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification

1627


What the difference is between execute, execute Query, execute Update?

589


What is difference between java and java ee?

764


What are keywords in java?

770


What is a parameter in java?

744


What does int [] mean in java?

763


What is string builder in java?

764


Which types of exceptions are caught at compile time?

784


What is hotjava?

743


Who is founder of java?

749


How does a for loop work?

741


What is java virtual machine and how it is considered in context of java’s platform independent feature?

855


Which is better list or arraylist in java?

664


Can a static class have a constructor?

762


What string is utf8?

741