ICSE Class 10 Computer Applications Question 16 of 17

Encapsulation — Question 3

Back to all questions
3
Question

Question 3

If a local variable is having the same name as that of a global class element, then it

  1. hides the global variable
  2. gets hidden by global variable
  3. produces an error
  4. none of the above
Answer

hides the global variable

Reason — If a local variable is having the same name as that of a global class element, the system resolves the name to the most local scope available i.e., most local variable with the same name will be considered. The global variable will be hidden by the local variable.