图片源于:hsp
package com_cc.Private;
/**
* @author CC
* @version 1.0
*/
public class 成员内部类 {
public static void main(String[] args) {
//访问成员内部类的方式
//1
out.inner c = new out().new inner();
c.f();
c.say();
//2
//在外部类中定义一个方法
out.inner c2 = new out().getinner();
c2.say();
c2.f();
}
}
class out{
int a = 3;
class inner{
int a = 5;
void f(){
System.out.println("内部类的a " + a);
System.out.println("外部类的a " + out.this.a);//方式:外部类名称.this+
}
void say(){
System.out.println("内部类");
}
}
public inner getinner(){
return new inner();
}
}