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

If system.exit (0); is written at the end of the try block, will the finally block still execute?

609


Is array primitive data type in java?

525


What is == in java?

555


Which sort is best in java?

518


What happens if we don’t define serial version uid?

560






What is method overloading with type promotion?

575


What is size of int in java?

540


Explain the significance of class loaders in bootstrap?

491


What are decalarations?

630


Explain the significance of listiterator.

575


What is autoboxing and unboxing?

575


What is a class variable?

559


How do you sort an array in java?

531


How do you download stubs from Remote place?

1350


What is the use of default method in interface in java? Explain

539