Explain Global variables in Packages?

Answer Posted / preetesh

There is no term as Global variable in Java.
Types of variable: 1) Local Variable declared within method.
2) Instance Variable declared within class but outside
method.
3) Class Variable
4) Parameters are also treated as variables

Example:
--------
public class Global {
public static int i = 25;
public static String s = "Preetesh";
}

//Such members can be accessed as:

public class Test {
public static void main(String[] args)
{
Global.i = Global.i + 100;
Global.s = "Java";
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you generate random numbers in java?

581


Difference between static binding and dynamic binding?

564


What is Classloader in Java?

634


What do you understand by java virtual machine?

705


Why is stringbuffer thread safe?

566






State the significance of public, private, protected class?

649


What is the old name of java?

501


What is the functionality of the stub?

571


Where we write javascript code in html page?

554


Explain java coding standards for constants?

573


What is the largest number a double can hold?

558


Explain the purpose of garbage collection in Java?

569


What is collection sort in java?

551


What is string manipulation?

492


What is a short in java?

497