-
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);}
}
}
-
- Protocol: https
- Host Name: www.interviewmania.com
- Port Number: -1
- All of above
- 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.