-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShadowing.java
More file actions
41 lines (32 loc) · 999 Bytes
/
Copy pathShadowing.java
File metadata and controls
41 lines (32 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package Method;
// Java program to Demonstrates Shadowing in Java
// Class 1 and 2
// Outer Class
public class Shadowing {
public static void main(String[] args)
{
// Accessing an inner class by
// creating object of outer class inside main()
Shadowing obj = new Shadowing();
Shadowing.innerShadowing innerObj
= obj.new innerShadowing();
// Calling method defined inside inner class
// inside main() method
innerObj.print();
}
// Custom instance variable or member variable
String name = "Outer John";
// Nested inner class
class innerShadowing {
// Instance variable or member variable
String name = "Inner John";
// Method of this class to
// print content of instance variable
public void print()
{
// Print statements
System.out.println(name);
System.out.println(Shadowing.this.name);
}
}
}