内部类:顾名思义,就是一个类中的类
特征:内部类中可以调用外部类的属性和方法;外部类不能调用内部类的属性和方法
上代码:package com.xg;
public class testNBclass {
public static void main(String[] args) {
System.out.println("blow is the result display");
OuterClass out = new OuterClass();
OuterClass.InnerClass inner = new OuterClass().new InnerClass();
out.OuterMethod();
inner.InnerMethod();
}
}
class OuterClass
{
int outer = 10;
public void OuterMethod(){
System.out.println("This is the method of the outer class");
}
class InnerClass
{
int inner = 100;
public void InnerMethod(){
System.out.println("This is the method of the inner class");
System.out.println("InnerClassVariables+OuterClassVariables = "+(inner+outer));
}
}
}
二:匿名内部类
1.概念
匿名内部类:



