为什么输出是"空"(null)
编写一个输出本地IP的方法,源码入下:
import java.net.*;
public class TestIP
{
public static void main(String args[])
{
InetAddress ia = null;
String s = null;
try
{
s = ia.getHostAddress();
}
catch(Exception e)
{
}
System.out.println(s);
}
}
可输出结果是null.为什么?