Scope Variables

Questions by sudhakar_bvr   answers by sudhakar_bvr

Showing Answers 1 - 4 of 4 Answers

satyarajasekhar

  • Jun 11th, 2006
 

A variable's scope is the region of a program within which the variable can be referred to by its simple name.

The location of the variable declaration within your program establishes its scope and places it into one of these four categories:

 1) Member variable - A member variable is a member of a class or an object. It is declared within a class but outside of any method or constructor. A member variable's scope is the entire declaration of the class. However, the declaration of a member needs to appear before it is used when the use is in a member initialization expression.

 2) Local variable -You declare local variables within a block of code. In general, the scope of a local variable extends from its declaration to the end of the code block in which it was declared.

 3)Method parameter - Parameters are formal arguments to methods or constructors and are used to pass values into methods and constructors. The scope of a parameter is the entire method or constructor for which it is a parameter.

 4) Exception handler parameter - Exception-handler parameters are similar to parameters but are arguments to an exception handler rather than to a method or a constructor. The scope of an exception-handler parameter is the code block between { and } that follow a catch statement.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions