Examveda

What will be the output of the following Java code?
import java.net.*;
class networking 
{
    public static void main(String[] args) throws MalformedURLException 
    {
        URL obj = new URL("https://www.example.com/javamcq");
        System.out.print(obj.getProtocol());
    }
}

A. http

B. https

C. www

D. com

Answer: Option B

Solution (By Examveda Team)

The correct answer is Option B: https.
Let's break down why:
The code uses the java.net.URL class, which is designed to work with URLs (Uniform Resource Locators).
A URL is essentially an address for a resource on the internet, like a webpage.
The line URL obj = new URL("https://www.example.com/javamcq"); creates a new URL object named 'obj'. This object represents the URL "https://www.example.com/javamcq".
The obj.getProtocol() method is called. This method specifically extracts the protocol part of the URL.
The protocol is the first part of a URL that indicates how the data will be transferred. Common protocols are "http" and "https".
In the given URL "https://www.example.com/javamcq", the protocol is "https".
Therefore, obj.getProtocol() will return "https", which is then printed to the console using System.out.print().

This Question Belongs to Java Program >> Java Serialization And Networking

Join The Discussion

Comments (1)

  1. Ganesh Commn
    Ganesh Commn:
    2 months ago

    Correct option is https

Related Questions on Java Serialization and Networking

What is Java Serialization?

A. The process of converting an object into a byte stream

B. The process of converting a byte stream into an object

C. The process of converting an object into a text file

D. The process of converting a text file into an object