Skip to content

Commit 0128224

Browse files
committed
add instance variable hiding class
1 parent 13d226c commit 0128224

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.scope.method;
2+
3+
/**
4+
* Created by Gebruiker on 5/6/2018.
5+
*/
6+
public class MethodHidingDemo {
7+
public static void main(String[] args) {
8+
9+
}
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.scope.variable;
2+
3+
/**
4+
* Created by Gebruiker on 5/6/2018.
5+
*/
6+
public class HideVariable {
7+
8+
private String instanceVariable = "this is instance variable";
9+
10+
HideVariable() {
11+
instanceVariable = "constructor local variable";
12+
System.out.println(instanceVariable);
13+
}
14+
15+
public void printLocalVariable() {
16+
instanceVariable = "method local variable";
17+
System.out.println(instanceVariable);
18+
}
19+
20+
public void printInstanceVariable() {
21+
System.out.println(this.instanceVariable);
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.scope.variable;
2+
3+
/**
4+
* Created by Gebruiker on 5/6/2018.
5+
*/
6+
public class VariableHidingDemo {
7+
public static void main(String[] args) {
8+
HideVariable variable = new HideVariable();
9+
variable.printLocalVariable();
10+
variable.printInstanceVariable();
11+
}
12+
}

0 commit comments

Comments
 (0)