Explain about global variables in Java?

Answers were Sorted based on User's Feedback



Explain about global variables in Java?..

Answer / ravikiran(aptech mumbai)

global variables are declared globally and not inside any
method.
They are applicable to all the parts of the class

Is This Answer Correct ?    11 Yes 1 No

Explain about global variables in Java?..

Answer / 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

Explain about global variables in Java?..

Answer / niranjanravi

Global variables are not possible in java because the
concept of Encapsulation is eliminated here.it is not in
the main() method where we declare variables.

Is This Answer Correct ?    5 Yes 8 No

Post New Answer

More Core Java Interview Questions

What is singleton class?

16 Answers   3i Infotech, 7 Seas, ABC, Amdocs, Cap Gemini, Oracle, Persistent, TCS, Techforza,


WHAT IS THE MEANING OF ALL TYPE OF BUZZWORDS?

4 Answers  


What is another word for methodology?

0 Answers  


When we r go to abstract class and when we go to Interface? i have confusion this question while in interview plz clarify

3 Answers   HCL, Photon,


What is Classloader in Java?

0 Answers  






How to perform quicksort in java?

0 Answers  


What is empty list in java?

0 Answers  


What is the importance of main method in Java?

0 Answers  


What is a pointer and does java support pointers?

0 Answers  


What is difference between class and object in java?

0 Answers  


What is the Dictionary class?

1 Answers  


What is the relationship between class and object?

0 Answers  


Categories