ICSE Class 9 Computer Applications Question 7 of 10

Working with Methods — Question 7

Back to all questions
7
Question

Question 7

Explain the scope of variables in Java

Answer

Scope of the variable determines in which parts of the program the variable is accessible. It is of the following types:

  1. 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.
  2. 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.
  3. Instance Variables (non-static variable) — The member variables that store the state of an object are known as instance variables.
  4. Class Variables (static variable) — A variable declared in a class with the static modifier is called a class variable.