toString()是个非static方法,也就是说你调用它,必须用实例调用
而不是类名调用的static方法.
InetAddress这个东东没用过,如果他是一个类的话,
InetAddress netAddress = new InetAddress();
netAddress.toString();
这样应该是合法的.

解决方案 »

  1.   

    static是关键字声明的是静态方法,使用时不用实例化,通过类名访问。
    如 String.valueOf(char c);
     
      

  2.   

    import java.net.*;
    import java.net.UnknownHostException;public class a{
       public static void main(String [] args)throws Exception{
         System.out.println(InetAddress.getLocalHost().toString());
       }
    }
    注意:InetAddress 是不可以用 new 来创建对象,即其不提供你构造函数,这种做法在Java中很普遍.限制用户按其设置创建对象.
       你只能使用:
    InetAddress.getAllByName(
          InetAddress.getByAddress(
          InetAddress.getByAddress(
          InetAddress.getByName(
          InetAddress.getLocalHost(
      这几类InetAddress提供的静态方法来创建对象.然后再调用其.toString()方法.
      

  3.   

    to LPRG(指间沙) :能说一下为什么要这么做,不用构造函数??
    难道说东西已存在只是java对象化了???
      

  4.   

    回复人: LPRG(指间沙) ( ) 信誉:100  
    ====================================同意