Skip to content

Instantly share code, notes, and snippets.

@vinimonteiro
Last active July 11, 2022 06:31
Show Gist options
  • Save vinimonteiro/1443b3cb2c9b974a20ea21f915b5b5bf to your computer and use it in GitHub Desktop.
Save vinimonteiro/1443b3cb2c9b974a20ea21f915b5b5bf to your computer and use it in GitHub Desktop.
Inner Class Shadowing
package com.vinimo;
public class OuterClass {
public int age = 30;
class InnerClass {
public int age = 20;
void methodInInnerClass(int age) {
System.out.println("age = " + age);
System.out.println("this.age = " + this.age);
System.out.println("OuterClass.this.age = " + OuterClass.this.age);
}
}
public static void main(String[] args) {
OuterClass st = new OuterClass();
OuterClass.InnerClass fl = st.new InnerClass();
fl.methodInInnerClass(37);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment