Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. What is the advantage of using 2D jagged array over 2D rectangular array?
  1.    Easy initialization of elements
  2.    Allows unlimited elements as well as rows which had '0' or are empty in nature
  3.    All of the mentioned
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Allows unlimited elements as well as rows which had '0' or are empty in nature


In many applications where 2 dimensional arrays are used,not all rows need to have all the elements i.e they are sparse.Many rows have 0 elements.In such cases it is better to use 2D jagged arrays as they allow unequal number of elements in each row and also allow for empty
rows.


Question 2. Choose Output for the following set of code :
static void Main(string[] args){    string s1 = "Hello" + " I " + "Love" + " ComputerScience ";    Console.WriteLine(s1);    Console.ReadLine();}
  1.    HelloILoveComputerScience
  2.    Hello I Love ComputerScience
  3.    Compile time error
  4.    Hello
 Discuss Question
Answer: Option B. -> Hello I Love ComputerScience


Here '+' defined operator works as concatenation for strings.
Output : Hello I Love ComputerScience.


Question 3. Which statement is correct about following set of code ? int[, ]a={{5, 4, 3},{9, 2, 6}};
  1.    'a' represents 1-D array of 5 integers
  2.    a.GetUpperBound(0) gives 9
  3.    'a' represents rectangular array of 2 columns and 3 arrays
  4.    a.GetUpperBound(0) gives 2
 Discuss Question
Answer: Option C. -> 'a' represents rectangular array of 2 columns and 3 arrays




Question 4. Which of these data type values is returned by equals() method of String class?
  1.    char
  2.    int
  3.    boolean
  4.    All of the mentioned
 Discuss Question
Answer: Option C. -> boolean


equals() method of string class returns boolean value true if both the strings are equal and false if they are unequal.


Question 5. What will be the output for the given code snippet?
static void Main(string[] args)  {      string s = " i love you";      Console.WriteLine(s.IndexOf('l') + "  " + s.lastIndexOf('o') + "  " + s.IndexOf('e'));      Console.ReadLine();  }
  1.    3 5 7
  2.    4 5 6
  3.    3 9 6
  4.    2 4 6
 Discuss Question
Answer: Option C. -> 3 9 6


indexof('l') and lastIndexof('o') are pre defined functions which are used to get the index of first and last occurrence of
the character pointed by l and c respectively in the given array.
Output : 3, 9, 6


Question 6. What will be the output of the following set of code?
class sum    {     public int x;     public int y;     public  int add (int a,  int b)     {         x = a + b;         y = x + b;         return 0;     } }     class Program {     static void Main(string[] args)     {         sum obj1 = new sum();         sum obj2 = new sum();            int a = 2;         obj1.add(a,  a + 1);         obj2.add(5,  a);         Console.WriteLine(obj1.x + "  " + obj2.y);              Console.ReadLine();     } }
  1.    6, 9
  2.    5, 9
  3.    9, 10
  4.    3, 2
 Discuss Question
Answer: Option B. -> 5, 9


Here, a = 2, a + 1 = 2 + 1 = 3.
So, a = 2, b = 3.
x = 2 + 3 = 5.
y = 5 + 3 = 8.
Similarly, a = 5, b = a + 1 = 4.
y = 5 + 4 = 9.
Output : 5, 9.


Question 7. What will be the output for the given set of code?
static void Main(string[] args) {     String c = "Hello";     String a = c + "Bye";     Console.WriteLine(a);     Console.ReadLine(); }
  1.    Hello Bye"
  2.    HelloBye"
  3.    Hello Bye
  4.    HelloBye
 Discuss Question
Answer: Option D. -> HelloBye


'+' operator method works in the form of concatenate method() and hence is used to join two strings together.
Output : HelloBye


Question 8. What would be the output for the following set of code?
static void Main(string[] args) {     String obj = "hello";     String obj1 = "world";        String obj2 = obj;     Console.WriteLine (obj.Equals(obj2) + "  " + obj2.CompareTo(obj) );     Console.ReadLine(); }
  1.    True True
  2.    False False
  3.    True 0
  4.    False 1
 Discuss Question
Answer: Option C. -> True 0


Equal() checks if two string objects 'obj' and 'obj2' are equal or not and hence returns true or false.Similarly, "CompareTo operator check two objects and since string obj2 = obj,it returns bool value '0'. Hence,they are equal.
Output : True 0


Question 9. What will be the output of given set of code?
static void main(string[] args) {     int i;     int res = fun (out i);     console.writeline(res);     console.readline(); } static int fun(out int i) {     int s = 1;     i = 7;     for (int j = 1; j <= i; j++ )     s = s * j;     return s; }
  1.    4490
  2.    5040
  3.    5400
  4.    3500
 Discuss Question
Answer: Option B. -> 5040




Question 10. What will be the output the of given set of code?
static void Main(string[] args) {     int [] a = {1, 2, 3, 4, 5};     fun(a);     Console.ReadLine(); } static void fun(params int[] b ) {     for (int i = 0; i < b.Length; i++)     {         b[i] = b[i] * 5 ;         Console.WriteLine(b[i] + "");     } }
  1.    1, 2, 3, 4, 5
  2.    5, 10, 15, 20, 25
  3.    5, 25, 125, 625, 3125
  4.    6, 12, 18, 24, 30
 Discuss Question
Answer: Option B. -> 5, 10, 15, 20, 25




Latest Videos

Latest Test Papers