250+ TOP MCQs on UrI Class and Answers

C# MCQs on Url class in C# Programming Language.

1. What does URL stand for?
a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch

Answer: a
Clarification: None.

2. Which of these exceptions is thrown by the URL class’s constructors?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException

Answer: c
Clarification: None.

3. What does the following form define?

  Protocol://HostName/FilePath?Query

a) Protocol specifies the protocol being used, such as HTTP
b) HostName identifies a specific server, such as mhprofessional.com or www.google.com
c) FilePath specifies the path to a specific file
d) All of the mentioned

Answer: d
Clarification: By definition.

4. Which of these classes is used to encapsulate IP address and DNS?
a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler

Answer: c
Clarification: InetAddress class encapsulates both IP address and DNS, we can interact with this class by using the name of an IP host.

5. Which of these is a standard for communicating multimedia content over email?
a) http
b) https
c) Mime
d) httpd

Answer: c
Clarification: MIME is an internet standard for communicating multimedia content over email. The HTTP protocol uses and extends the notion of MIME headers to pass attribute pairs between HTTP client and server.

6. What does the following method specify?

   public static WebRequest Create(string requestUriString)

a) Creates a WebRequest object for the URI specified by the string passed by requestUriString
b) The object returned will implement the protocol specified by the prefix of the URI
c) The object will be an instance of the class that inherits WebRequest
d) All of the mentioned

Answer: d
Clarification: Creates a WebRequest object for the URI specified by the string passed by requestUriString. The object returned will
implement the protocol specified by the prefix of the URI. Thus, the object will be an instance of a class that inherits WebRequest. A NotSupportedException is thrown if the requested protocol is not available. A UriFormatException is thrown if the URI format is invalid.

7. What will be the output of the following C# code?

  1.   class Program
  2.   {
  3.       static void Main(string[] args)
  4.       {
  5.           int ch;
  6.           HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://www.McGraw-Hill.com");
  7.           HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
  8.           Stream istrm = resp.GetResponseStream();
  9.           for (int i = 1 ;  ;i++)
  10.           {
  11.               ch = istrm.ReadByte();
  12.               if (ch == -1)
  13.               break;
  14.               Console.Write((char)ch);
  15.               if ((i % 400) == 0)
  16.               {
  17.                   Console.Write("nPress Enter.");
  18.                   Console.ReadLine();
  19.               }
  20.           }
  21.           resp.Close();
  22.       }
  23.   }

a) html
b) text
c) html/text
d) text/html

Answer: d
Clarification: The following program obtains the hypertext contained at a specific website. The program displays the hypertext on the screen.

8. What will be the output of the following C# code?

  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.          Uri obj = new Uri("csharpmcq");
  6.          Console.WriteLine(obj.AbsoluteUri);
  7.          Console.ReadLine();
  8.      }
  9.  }

a)
b) .com
c) www..com
d) csharpmcq

Answer: d
Clarification: AbsoluteUri is used to know the full URL of an URL object.
Output:

 https://www..com/csharpmcq

9. Which of these data members of HttpResponse class is used to store the response from a http server?
a) status
b) address
c) statusResponse
d) statusCode

Answer: d
Clarification: When we send a request to http server it responds with a status code. This status code is stored in statusCode and the textual equivalent is stored in reasonPhrase.

10. Which of these classes is used to access actual bits or content information of a URL?
a) URL
b) URLDecoder
c) URLConnection
d) All of the mentioned

Answer: d
Clarification: URL, URLDecoder and URLConnection – all these are used to access information stored in the URL.

Leave a Reply

Your email address will not be published. Required fields are marked *