hiding test
This commit is contained in:
parent
5b7c29e7bf
commit
6adc92c451
|
@ -5,5 +5,9 @@ package com.baeldung.scope.variable;
|
||||||
*/
|
*/
|
||||||
public class ChildVariable extends ParentVariable {
|
public class ChildVariable extends ParentVariable {
|
||||||
|
|
||||||
String instanceVariable = "parent variable";
|
String instanceVariable = "child variable";
|
||||||
|
|
||||||
|
public void printInstanceVariable() {
|
||||||
|
System.out.println(instanceVariable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,8 @@ package com.baeldung.scope.variable;
|
||||||
public class ParentVariable {
|
public class ParentVariable {
|
||||||
|
|
||||||
String instanceVariable = "parent variable";
|
String instanceVariable = "parent variable";
|
||||||
|
|
||||||
|
public void printInstanceVariable() {
|
||||||
|
System.out.println(instanceVariable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,11 @@ public class VariableHidingDemo {
|
||||||
HideVariable variable = new HideVariable();
|
HideVariable variable = new HideVariable();
|
||||||
variable.printLocalVariable();
|
variable.printLocalVariable();
|
||||||
variable.printInstanceVariable();
|
variable.printInstanceVariable();
|
||||||
|
|
||||||
|
ParentVariable parentVariable = new ParentVariable();
|
||||||
|
ParentVariable childVariable = new ChildVariable();
|
||||||
|
|
||||||
|
parentVariable.printInstanceVariable();
|
||||||
|
childVariable.printInstanceVariable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue