Explain about global variables in Java?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
give an example for encapsulation?
What is the difference between C++ and Java and your preferences?
when System.out.println("") is executed what happens in the back ground?
How thread scheduler schedule the task?
In case of inheritance what is the execution order of constructor and destructor?
What do you mean by garbage collection used in java?
What is final int?
What are the types of statement? explain
Can two objects have same hashcode?
Is 0 an irrational number?
Which class represents the socket that both the client and server use to communicate with each other?
what is business objects?