Home » JAVA Programming » Networking » Question
  1. What is the output of this program?
    import java.io.*;  
    import java.net.*;
    public class URL_Example
    {
    public static void main(String[] args)
    {
    try
    {
    URL url=new URL("https://www.interviewmania.com/programming");
    System.out.println("Protocol: "+url.getProtocol());
    System.out.println("Host Name: "+url.getHost());
    System.out.println("Port Number: "+url.getPort());
    } catch(Exception e){System.out.println(e);}
    }
    }
    1. Protocol: https
    2. Host Name: www.interviewmania.com
    3. Port Number: -1
    4. All of above
    5. None of these
Correct Option: D

getProtocol() give protocol which is http
getUrl() give name domain name
getPort() Since we have not explicitly set the port, default value that is -1 is printed.



Your comments will be displayed only after manual approval.