Computer Applications
Answer
Scope of the variable determines in which parts of the program the variable is accessible. It is of the following types:
- Local Variables — The variables declared inside a method or block are called local variables. The scope of local variables is limited to the method or the block they are declared in.
- Parameter Variables — The variables used as arguments in the method prototype are called parameter variables. Their scope is limited to the method where they are being used.
- Instance Variables (non-static variable) — The member variables that store the state of an object are known as instance variables.
- Class Variables (static variable) — A variable declared in a class with the static modifier is called a class variable.
Related Questions
What does void signify in the method prototype?
Explain the difference between actual and formal parameters.
Explain static and non-static methods.
Write a class that contains the following two methods:
- public static double celsiusToFahrenheit(double celsius)
- public static double fahrenheitToCelsius(double fahrenheit)
Use the following formulas for temperature conversion:
- fahrenheit = (9.0 / 5) * celsius + 32
- celsius = (5.0 / 9) * (fahrenheit - 32)
Finally, invoke these methods in BlueJ to convert some test values.