package cn.itcast_02;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
/*
* 如果一个类没有构造方法
* A:成员全部是静态(Math ,Arrays , Collections)
* B:单例设计模式(Runtime)
* C:类中也就静态方法返回该类对象(InetAdddress)
* class Dome(){
* private Dome(){}
*
* public static Dome getXxx(){
* return new Dome();
* }
* }
*
* 看InetAddress的成员方法:
* public static InetAddress getBybName(String host) :根据主机名或者IP地址的字符串
* 表示得到IP地址对象
*/
public class IntAddress类的概述和使用 {
public static void main(String[] args) throws IOException {
InetAddress it = InetAddress.getByName("空白卷");
//获取两个东西 主机名和IP地址
//public String getHostName()
String name = it.getHostName();
//Public String getHostAddress()
String ip = it.getHostAddress();
System.out.println(name+"-----"+ip);
}
}
IntAddress类的概述和使用
于 2020-10-28 22:55:40 首次发布