java 实例化一个类是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26703694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:26:49 来源:igfitidea点击:
What does it mean to instantiate a class?
提问by user3443378
This is the criteria:
这是标准:
- The nsLookup class is instantiated with a string that de?nes the host to be queried.
- The constructor instantiates the InetAddress object using this string.
- A method is designed to resolve the lookup query. The query can return multiple IP addresses if they exist. These should be returned to the GUI as an array of String objects for display.
- nsLookup 类使用定义要查询的主机的字符串进行实例化。
- 构造函数使用此字符串实例化 InetAddress 对象。
- 设计了一种方法来解析查找查询。查询可以返回多个 IP 地址(如果存在)。这些应该作为 String 对象的数组返回给 GUI 以供显示。
This is the code:
这是代码:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class NsLookup {
private InetAddress inet = null;
public void resolve(String host) {
try {
inet = InetAddress.getByName(host);
System.out.println("Host name : " + inet.getHostName());
System.out.println("IP Address: " + inet.getHostAddress());
}
catch (UnknownHostException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
NsLookup lookup = new NsLookup();
lookup.resolve(args[0]);
}
}
Please help me with examples if possible?
如果可能,请帮我举例?
回答by phantom
To instantiate something is to create an object of that type. You are doing that here:
实例化某物就是创建该类型的对象。你在这里这样做:
NsLookup lookup = new NsLookup();
and here:
和这里:
inet = InetAddress.getByName(host);
Hope this helped, good luck!
希望这有帮助,祝你好运!