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

Explain the significance of listiterator.

0 Answers  


When should I use stringbuffer?

0 Answers  


Can you declare a private method as static?

0 Answers   TCS,


What is the meaning of find and replace?

0 Answers  


What are Font and FontMetrics classes?

1 Answers  






What is break and continue statement?

0 Answers  


Can we add default constructor to Servlet?

1 Answers   Fidelity,


Is 0 true or is 1 true?

0 Answers  


What are the two environment variables that must be set in order to run any java programs?

0 Answers  


Can a Byte object be cast to a double value?

3 Answers   KO,


Is it possible to use Semaphore/ Mutex in an Interrupt Handler?

0 Answers   Ciena,


What is a private class in java?

0 Answers  


Categories