Skip to content

Instantly share code, notes, and snippets.

@Kaushal28
Created July 24, 2019 05:29
Show Gist options
  • Save Kaushal28/7d4689c87772af4807ca9a27e09867a0 to your computer and use it in GitHub Desktop.
Save Kaushal28/7d4689c87772af4807ca9a27e09867a0 to your computer and use it in GitHub Desktop.
class Test {
int instanceVar = 10;
void hideInstance() {
int instanceVar = 15;
System.out.println("Local variable: " + instanceVar); //This will print local variable, as instance variable is hidden
//To access instance variable here, use this.instanceVariable
System.out.println("Instance variable: " + this.instanceVar);
}
}
public class InstanceVarHiding {
public static void main (String[] args) {
Test test = new Test();
test.hideInstance();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment