add instance variable hiding class
This commit is contained in:
parent
13d226c97b
commit
0128224acc
@ -0,0 +1,10 @@
|
||||
package com.baeldung.scope.method;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/6/2018.
|
||||
*/
|
||||
public class MethodHidingDemo {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.baeldung.scope.variable;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/6/2018.
|
||||
*/
|
||||
public class HideVariable {
|
||||
|
||||
private String instanceVariable = "this is instance variable";
|
||||
|
||||
HideVariable() {
|
||||
instanceVariable = "constructor local variable";
|
||||
System.out.println(instanceVariable);
|
||||
}
|
||||
|
||||
public void printLocalVariable() {
|
||||
instanceVariable = "method local variable";
|
||||
System.out.println(instanceVariable);
|
||||
}
|
||||
|
||||
public void printInstanceVariable() {
|
||||
System.out.println(this.instanceVariable);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.baeldung.scope.variable;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/6/2018.
|
||||
*/
|
||||
public class VariableHidingDemo {
|
||||
public static void main(String[] args) {
|
||||
HideVariable variable = new HideVariable();
|
||||
variable.printLocalVariable();
|
||||
variable.printInstanceVariable();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user