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

Why are global variables used?

490


How can an object be unreferenced?

532


Can we have two main methods in a java class?

528


What is methods in java?

504


What is boolean keyword in java?

585






What is a java lambda expression?

545


How is Object Oriented Programming different from Procedure Oriented Programming?

580


How many tetrahedral voids are there in bcc?

536


What is navigable map in java?

509


When is the finalize() called? What is the purpose of finalization?

569


Can we increase array size dynamically in java?

494


What is a arraylist in java?

543


Explain the importance of finalize() method.

558


How is a structure different from array ?

569


What is a byte string?

607