Created
July 24, 2019 05:29
-
-
Save Kaushal28/7d4689c87772af4807ca9a27e09867a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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