内部类-非静态内部类|静态内部类|匿名内部类
package com.weitip.oop;
/**
* Created by IntelliJ IDEA.
* User: loong
* Date: 2019/3/11
* Time: 15:35
* Description: com.weitip.oop
**/
public class InnerClass {
public static void main(String[] args) {
Outer.Inner inner = new Outer().new Inner();
inner.show();
Outer.Inner2 inner2 = new Outer.Inner2();
inner2.show();
}
}
class Outer{
private int age = 20;
class Inner{
int age = 999;
public void show(){
int age = 999999;
System.out.println("外部类属性age:" + Outer.this.age);
System.out.println("内部类属性age:" + this.age);
System.out.println("局部变量age:" + age);
}
}
static class Inner2{
public static void show() {
System.out.println("内部静态类被调用");
}
}
}package com.weitip.oop;
/**
* Created by IntelliJ IDEA.
* User: loong
* Date: 2019/3/11
* Time: 16:01
* Description: com.weitip.oop
**/
public class AnonymousInnerClass {
public static void test(AA a){
a.aa();
}
public static void main(String[] args) {
AnonymousInnerClass.test(new AA(){
@Override
public void aa() {
System.out.println("匿名内部类被调用");
}
});
}
}
interface AA{
void aa();
}
