本帖最后由 遮天 于 2014-6-12 16:19 编辑
- /*
- 内部类
- */
- class Outer //声明外部类
- {
- private String name;
- class Inner //声明内部类
- {
- int age;
- Inner(String n, int a)
- {
- name = n;
- age = a;
- }
- void function()
- {
- System.out.println("姓名:"+name+"____年龄:"+age);
- }
- }
- void method()
- {
- Inner in = new Inner("脚本小子", 12);
- in.function();
- }
- }
- class Demo
- {
- public static void main(String[] args)
- {
- Outer o = new Outer();
- o.method();
- }
- }
- 为什么内部类的构造函数写成下面的情况时会错?不懂求解......
- Inner(String name, int age)
- {
- this.name = name;
- this.age = age;
- }
复制代码 |
|