java内部类之方法内部类

来源:互联网 发布:sql查询表语句怎么写 编辑:程序博客网 时间:2024/05/21 11:33

方法内部类

  1. 在方法内部定义。
  2. 可以访问外部类的成员变量和方法,还可以访问方法中final局部变量。
  3. 外部类不能访问其成员变量和方法,但可以建立它的对象。
  4. 不能写访问修饰符,不能使用static。

代码块

代码块语法遵循标准markdown代码,例如:

@requires_Gerald_Jones    class one1{    private int x = 0;    public void two1(int a, int b)    {        x = a + b;        //System.out.println(x);        class three1        {            public void four1()            {                System.out.println(x);            }        }        //新建类的对象        three1 t = new three1();        t.four1();    }}public class InnerMethod {    public static void main(String [] agrs)    {        one1 o = new one1();        o.two1(10, 23);    }}
0 0