为什么在定义一个类中可以在方法中调用这个类的对象?
class person
{   String name;
    public person()
    {
    }
    public person(String name)
    {
       this.name=name;
    }
    public void fun1()
   {
    System.out.println(name);
   }
   public void fun2()
   {
    person a2 = new person("a2");此处在定义这个person类中的fun2()方法中又创建了这个person类的对象?
    a2.fun1();
   }
}

解决方案 »

  1.   

    不能将自己的对象定义成自己的属性。但局部变量是可以的。
    public class test{
       public static void main(){
          test t = new test();
       }
    }
      

  2.   

    定义成自己的属性也是可以的
    比如
    class 类别 {
      类别 childs = null;
      类别 parent = null;
      public static void main(String[] args) {
         类别 obj = new 类别();
      }
    }
      

  3.   

    http://topic.csdn.net/t/20050526/14/4037386.html