当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 非常感谢 ......
 ·简单问题(但对我很难)    »显示摘要«
    摘要: 现在我申请了一个域名www.myname.com,我用的是自已的服务器,接宽带后得到固定ip 219。138。125。45,现在的问题是怎么将这个域名和我的服务器绑定。 很急 ......


传值与传址的简单问题

代码;  
   
  public   class   PassByValue1   {  
      int   i=0;  
      PassByValue1(int   newValue)   {  
          i=newValue;  
      }  
      static   void   changeInt(int   value){  
          value=98;  
          System.out.println("value   in   changeInt()="+value);  
      }  
      static   void   changeObjRef(PassByValue1   obj){  
          obj=new   PassByValue1(99);  
          System.out.println("obj.i   in   changeObjRef()="+obj.i);  
      }  
      static   void   changeObjAttr(PassByValue1   obj){  
          obj.i=100;  
          System.out.println("obj.i   in   changeObjAttr()="+obj.i);  
      }  
      public   static   void   main(String[]   args)   {  
          int   value=2;  
          System.out.println("value   before   changeInt()="+value);  
          changeInt(value);  
          System.out.println("value   after   changeInt()="+value);  
          PassByValue1   obj=new   PassByValue1(2);  
          System.out.println("------------");  
          System.out.println("obj   before   changeObjRef()="+obj);  
          System.out.println("obj.i   before   changeObjRef()="+obj.i);  
          changeObjRef(obj);  
          System.out.println("obj.i   after   changeObjRef()="+obj.i);  
          System.out.println("obj   after   changeObjRef()"+obj);  
          System.out.println("------------");  
          System.out.println("obj   before   changeObjAttr()="+obj);  
          System.out.println("Obj.i   before   changeObjAttr()="+obj.i);  
          changeObjAttr(obj);  
          System.out.println("obj.i   after   changeObjAttr()="+obj.i);  
          System.out.println("obj   agter   changeObjAttr()="+obj);  
      }  
  }  
  结果:  
   
  value   before   changeInt()=2  
   
  value   in   changeInt()=98  
   
  value   after   changeInt()=2  
   
  ------------  
   
  obj   before   changeObjRef()=passbyvalue1.PassByValue1@5d87b2  
   
  obj.i   before   changeObjRef()=2  
   
  obj.i   in   changeObjRef()=99  
   
  obj.i   after   changeObjRef()=2  
   
  obj   after   changeObjRef()passbyvalue1.PassByValue1@5d87b2  
   
  ------------  
   
  obj   before   changeObjAttr()=passbyvalue1.PassByValue1@5d87b2  
   
  Obj.i   before   changeObjAttr()=2  
   
  obj.i   in   changeObjAttr()=100  
   
  obj.i   after   changeObjAttr()=100  
   
  obj   agter   changeObjAttr()=passbyvalue1.PassByValue1@5d87b2  
   
  如何理解以上结果?特别是  
  obj   before   changeObjRef()=passbyvalue1.PassByValue1@5d87b2  
   
  obj.i   before   changeObjRef()=2  
   
  obj.i   in   changeObjRef()=99  
   
  obj.i   after   changeObjRef()=2  
   
  obj   after   changeObjRef()passbyvalue1.PassByValue1@5d87b2  
   
  ------------  
   
  obj   before   changeObjAttr()=passbyvalue1.PassByValue1@5d87b2  
   
  Obj.i   before   changeObjAttr()=2  
   
  obj.i   in   changeObjAttr()=100  
   
  obj.i   after   changeObjAttr()=100  
   
  obj   agter   changeObjAttr()=passbyvalue1.PassByValue1@5d87b2  
 

NO.1   作者: weimenren

public   class   PassByValue1  
  {  
  int   i   =   0;    
  PassByValue1(int   newValue)  
  {  
  i   =   newValue;  
  }  
  static   void   changeInt(int   value)  
  {  
  value   =   98;  
  System.out.println("value   in   changeInt()   =   "   +   value);  
  }  
   
      static   void   changeObjRef(PassByValue1   obj)  
  {  
          obj   =   new   PassByValue1(99);  
          System.out.println("obj.i   in   changeObjRef()="   +   obj.i);  
      }  
  static   void   changeObjAttr(PassByValue1   obj)  
  {  
  obj.i   =   100;  
          System.out.println("obj.i   in   changeObjAttr()="   +   obj.i);  
      }  
      public   static   void   main(String[]   args)    
  {  
          int   value=2;  
          System.out.println("value   before   changeInt()="   +   value); //   value   =   2  
          changeInt(value); //   changeInt()   =   98   value   是局部变量,退出方法的时间,value分配的内存收回  
          System.out.println("value   after   changeInt()="+value);     //   value   =   2   故   value   =   2  
          PassByValue1   obj   =   new   PassByValue1(2); //    
          System.out.println("------------"); //-------------  
          System.out.println("obj   before   changeObjRef()="+obj); //   地址A  
          System.out.println("obj.i   before   changeObjRef()="+obj.i); //   obj.i   =   2    
          changeObjRef(obj); // obj.i   =   99   obj   在changeObjRef中重新分配了地址,  
  //要不你可以在方法中尝试一下,System.out.println(obj);你会发现地址变了,  
  //obj在方法中也是一个局部变量,退出方法的时间,内存收回  
          System.out.println("obj.i   after   changeObjRef()="+obj.i); //   obj.i   =   2   故obj.i   还是等于2  
          System.out.println("obj   after   changeObjRef()"+obj); //地址A   地址没有变,还是一开始    
  //PassByValue1   obj   =   new   PassByValue1(2); 时间的地址  
          System.out.println("------------");   //   --------    
          System.out.println("obj   before   changeObjAttr()="+obj);   //   地址A   地址没有变,还是一开始    
  //PassByValue1   obj   =   new   PassByValue1(2); 时间的地址  
          System.out.println("Obj.i   before   changeObjAttr()="+obj.i);   //   obj.i   =   2   还是原来的obj.i   =   2  
          changeObjAttr(obj);   //   obj.i   =   100   obj.i   重新赋值了,  
  //这个时间也更新了obj   中的i   的值,并记录到obj中,obj没有重新new,是初始的时间的那个  
  //PassByValue1   obj   =   new   PassByValue1(2);  
          System.out.println("obj.i   after   changeObjAttr()="+obj.i); //obj.i   =   100   所以obj.i变成了   100  
          System.out.println("obj   agter   changeObjAttr()="+obj);   //   地址A   地址没有变,还是一开始    
  //PassByValue1   obj   =   new   PassByValue1(2); 时间的地址,没有重新new  
   
      }  
  }  
   
 

NO.2   作者: Norwaywoods

http://expert.csdn.net/Expert/topic/1437/1437310.xml?temp=.699917  
   
   
  请看上面的贴子里我的回复。


 ·提问:动态链接库相关的概念    »显示摘要«
    摘要: 问题1:动态链接库中有输入/输出 函数的概念,我所理解的是输出函数是提供给外部程序调用的接口函数,如果我的理解没错的话,那输入函数是干什么用的呢?看了一些资料,说是动态链接库在调用另一个动态链接库的时候需要使用输入函数,很迷惑,哪位大侠能给我这个菜鸟解释解释? 问题2:在编写动态链接库的时候,我查看了bcb 的"importand notes",原文大意是如果在接口函数......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE