In which process, a local variable has the same name as one of the instance variables?
A) Serialization
B) Variable Shadowing
C) Abstraction
D) Multi-threading
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Answer: option B) Variable Shadowing
Variable Shadowing: If the local variable and instance variable have same name The value of the local variable will be printed(shadowing the instance variable), whenever you print (access) it in the method.
Example:
In the following Java example, the class ShadowTest has a method (show()). and two instance variables (name, age).
In the show() method there are two variables same as the instance variables (name and age).
When you invoke print (access) them in the method, the local variable values will be printed shadowing the instance ones.
Answer: (b) Variable Shadowing