Home » JAVA Programming » Networking » Question
  1. What is the output of this program?
    import java.net.*;
    public class networking_Example
    {
    public static void main(String[] args) throws UnknownHostException
    {
    InetAddress object1 = InetAddress.getByName("tcs.com");
    InetAddress object2 = InetAddress.getByName("interviewmania.com");
    boolean p = object1.equals(object2);
    System.out.print(p);
    }
    }
    1. 1
    2. 0
    3. true
    4. false
    5. None of these
Correct Option: D

InetAddress object1 = InetAddress.getByName(“tcs.com”); creates object object1 having DNS and IP address of tcs.com, InetAddress object2 = InetAddress.getByName(“interviewmania.com”); creates object2 having DNS and IP address of interviewmania.com , since both these address point to two different locations false is returned by object1.equals(object2);.



Your comments will be displayed only after manual approval.