commit
5222cb2485
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.scope.method;
|
||||||
|
|
||||||
|
|
||||||
|
public class BaseMethodClass {
|
||||||
|
|
||||||
|
public static void printMessage() {
|
||||||
|
System.out.println("base static method");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.scope.method;
|
||||||
|
|
||||||
|
|
||||||
|
public class ChildMethodClass extends BaseMethodClass {
|
||||||
|
|
||||||
|
public static void printMessage() {
|
||||||
|
System.out.println("child static method");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.baeldung.scope.method;
|
||||||
|
|
||||||
|
public class MethodHidingDemo {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ChildMethodClass.printMessage();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.scope.variable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Gebruiker on 5/7/2018.
|
||||||
|
*/
|
||||||
|
public class ChildVariable extends ParentVariable {
|
||||||
|
|
||||||
|
String instanceVariable = "child variable";
|
||||||
|
|
||||||
|
public void printInstanceVariable() {
|
||||||
|
System.out.println(instanceVariable);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.scope.variable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Gebruiker on 5/6/2018.
|
||||||
|
*/
|
||||||
|
public class HideVariable {
|
||||||
|
|
||||||
|
private String message = "this is instance variable";
|
||||||
|
|
||||||
|
HideVariable() {
|
||||||
|
String message = "constructor local variable";
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printLocalVariable() {
|
||||||
|
String message = "method local variable";
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printInstanceVariable() {
|
||||||
|
System.out.println(this.message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.scope.variable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Gebruiker on 5/7/2018.
|
||||||
|
*/
|
||||||
|
public class ParentVariable {
|
||||||
|
|
||||||
|
String instanceVariable = "parent variable";
|
||||||
|
|
||||||
|
public void printInstanceVariable() {
|
||||||
|
System.out.println(instanceVariable);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
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();
|
||||||
|
|
||||||
|
ParentVariable parentVariable = new ParentVariable();
|
||||||
|
ParentVariable childVariable = new ChildVariable();
|
||||||
|
|
||||||
|
parentVariable.printInstanceVariable();
|
||||||
|
childVariable.printInstanceVariable();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user