public interface A {
void setAll(int ID,String IP)
String getAll()
}
package test5
public class B implements A{
String IP
int ID
public void setAll(int ID,String IP) {
this.ID=ID
this.IP=IP
}
public String getAll() {
return "ID为: "+ID+"\t\t"+"IP为: "+IP
}
public static void main(String[] args) {
B b=new B()
b.setAll(1, "192.168.1.1")
System.out.println(b.getAll())
}
}
public static String getHostIpAddress() {String hostIp = ""
InetAddress netAddress = getInetAddress()
hostIp = getHostIp(netAddress)
return hostIp
}
public static InetAddress getInetAddress() {
try {
return InetAddress.getLocalHost()
} catch (UnknownHostException e) {
System.out.println("unknown host!")
}
return null
}
public static String getHostIp(InetAddress netAddress) {
if (null == netAddress) {
return null
}
String ip = netAddress.getHostAddress()// get the ip address
return ip
}
public static String getHostName(InetAddress netAddress) {
if (null == netAddress) {
return null
}
String name = netAddress.getHostName()// get the host address
return name
}