java 局部内部类的定义

  局部内部类定义:
    如果一个类定义在一个方法内部的,那么这就是一个局部内部类
 “局部”:指的事只有当前方法才能使用它,出了这个方法不能再使用,比如:main方法
 
 定义格式:
    修饰符 class 外部类名称{
    修饰符 返回值类型 外部类方法名称(参数类表){
   class 局部类名称
             //...
     }
    
 }
 
  类的权限修饰符:
 public > protected > (default)> private
 1.外部类:public/ protected
 2.成员内部类: public / protected / (default)/private
 3.局部内部类:什么都不写     

 

public class Outer {//外部类
	
	
	public void methodOuter() {//外部类方法
		class Inter{  //class 前面不写任何修饰符因为这是局部内部类
			int num=10;
			public void methodInter() {//局部内部类的方法
				System.out.println(num);
			}
		}Inter inter=new Inter();//inter内部类methodInter方法是不可以被调用的  只能被 methodOuter方法它使用,出来外部就不可以被使用
		inter.methodInter();// 引出外面后再用main 主方法调用methodInter方法
		
		
	}

}
public class Test01Main {

	public static void main(String[] args) {
			Outer outer=new Outer();
			outer.
	}

 

 

 

你可能感兴趣的:(java,内部类)