Skip to content

Commit 5222cb2

Browse files
authored
Merge pull request eugenp#4225 from MherBaghinyan/BAEL-1754
Bael 1754
2 parents 344c94d + 6adc92c commit 5222cb2

7 files changed

Lines changed: 93 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)