import java.io.*; import java.net.*; public class URLDemo { public static void main(String[] args) { try { URL url=new URL("https://www.sanfoundry.com/java-mcq"); 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);} } }
a) Protocol: http
b) Host Name: http://www.sanfoundry.com
c) Port Number: -1
d) All of the mentioned
d
Explanation: 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.