Variable shadowing with example

Showing Answers 1 - 3 of 3 Answers

In the below program local variable  is shadowed with field variable.
class shadowing
{
int  i=20;
System.out.print("Value of i:");
System.out.println(i);

void method()
{
int i=10;
System.out.print("Value of i:");
System.out.println(i);
}
System.out.print("Value of i:");
System.out.println(i);
}

OUTPUT:
Value of i:20
Value of i:10
Value of i:20

  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