KnowledgeBoat Logo
|
LoginJOIN NOW

Computer Applications

Explain the scope of variables in Java

User Defined Methods

29 Likes

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.

Answered By

18 Likes


Related Questions