logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Classes and Objects See What Others Are Saying!
  • Question
  • Which of the following statements is correct about the C#.NET code snippet given below?

    class Sample
    {
        private int i;
        public Single j;
        private void DisplayData()
        {
            Console.WriteLine(i + " " + j);
        }
        public void ShowData()
        {
            Console.WriteLine(i + " " + j);
        }
    }


  • Options
  • A. j cannot be declared as public.
  • B. DisplayData() cannot be declared as private.
  • C. DisplayData() cannot access j.
  • D. ShowData() cannot access to i.
  • E. There is no error in this class.

  • Correct Answer
  • There is no error in this class. 


  • More questions

    • 1. For the code snippet given below, which of the following statements are valid?

      public class MyContainer<T> where T: class, IComparable
      {
          //Insert code here
      }
      1. Class MyContainer requires that it's type argument must implement IComparable interface.
      2. Compiler will report an error for this block of code.
      3. There are multiple constraints on type argument to MyContainer class.
      4. Class MyContainer requires that its type argument must be a reference type and it must implement IComparable interface.

    • Options
    • A. 1 and 2 Only
    • B. 3 and 4 Only
    • C. 2 and 3 Only
    • D. All of the above
    • E. None of the above
    • Discuss
    • 2. Which of the following will be the correct output for the C#.NET program given below?

      namespace CuriousTabConsoleApplication
      { 
          class SampleProgram
          { 
              static void Main(string[] args)
              {
                  int a = 5; 
                  int s = 0, c = 0;
                  Proc(a, ref s, ref c);
                  Console.WriteLine(s + " " + c);
              }
              static void Proc(int x, ref int ss, ref int cc)
              {
                  ss = x * x;
                  cc = x * x * x;
              } 
          } 
      }

    • Options
    • A. 0 0
    • B. 25 25
    • C. 125 125
    • D. 25 125
    • E. None of the above
    • Discuss
    • 3. Which of the following jobs are done by Common Language Runtime?

      1. It provides core services such as memory management, thread management, and remoting.
      2. It enforces strict type safety.
      3. It provides Code Access Security.
      4. It provides Garbage Collection Services.

    • Options
    • A. Only 1 and 2
    • B. Only 3, 4
    • C. Only 1, 3 and 4
    • D. Only 2, 3 and 4
    • E. All of the above
    • Discuss
    • 4. Which of the following statements are correct about the C#.NET code snippet given below?

      if (age > 18 && no < 11)
          a = 25;
      1. The condition no < 11 will be evaluated only if age > 18 evaluates to True.
      2. The statement a = 25 will get executed if any one condition is True.
      3. The condition no < 11 will be evaluated only if age > 18 evaluates to False.
      4. The statement a = 25 will get executed if both the conditions are True.
      5. && is known as a short circuiting logical operator.

    • Options
    • A. 1, 3
    • B. 2, 5
    • C. 1, 4, 5
    • D. 3, 4, 5
    • E. None of these
    • Discuss
    • 5. Which of the following are the correct way to initialise the variables i and j to a value 10 each?

      1. int i = 10; int j = 10;
      2. int i, j;
        i = 10 : j = 10;
      3. int i = 10, j = 10;
      4. int i, j = 10;
      5. int i = j = 10;

    • Options
    • A. 2, 4
    • B. 1, 3
    • C. 3, 5
    • D. 4, 5
    • Discuss
    • 6. What is the output of the C#.NET code snippet given below?

      namespace CuriousTabConsoleApplication
      {
          public enum color
          { red, green, blue };
          
          class SampleProgram
          {
              static void Main (string[ ] args)
              {
                  color c = color.blue;
                  switch (c)
                  {
                      case color.red:
                          Console.WriteLine(color.red); 
                          break; 
                      
                      case color.green: 
                          Console.WriteLine(color.green); 
                          break; 
                      
                      case color.blue: 
                          Console.WriteLine(color.blue); 
                          break; 
                  } 
              } 
          } 
      }

    • Options
    • A. red
    • B. blue
    • C. 0
    • D. 1
    • E. 2
    • Discuss
    • 7. Which of the following statements is correct about the C#.NET code snippet given below?

      switch (id)
      {
          case 6: 
              grp = "Grp B"; 
              break;
          
          case 13:
              grp = "Grp D";
              break;
          
          case 1:
              grp = "Grp A";
              break;
          
          case ls > 20:
              grp = "Grp E";
              break ;
          
          case Else:
              grp = "Grp F";
              break;
      }

    • Options
    • A. Compiler will report an error in case ls > 20 as well as in case Else.
    • B. There is no error in this switch case statement.
    • C. Compiler will report an error only in case Else.
    • D. Compiler will report an error as there is no default case.
    • E. The order of the first three cases should be case 1, case 6, case 13 (ascending).
    • Discuss
    • 8. Which of the following statements are correct about the C#.NET code snippet given below?

      if (age > 18 || no < 11)
          a = 25;
      1. The condition no < 11 will get evaluated only if age > 18 evaluates to False.
      2. The condition no < 11 will get evaluated if age > 18 evaluates to True.
      3. The statement a = 25 will get evaluated if any one one of the two conditions is True.
      4. || is known as a short circuiting logical operator.
      5. The statement a = 25 will get evaluated only if both the conditions are True.

    • Options
    • A. 1, 4, 5
    • B. 2, 4
    • C. 1, 3, 4
    • D. 2, 3, 5
    • E. None of these
    • Discuss
    • 9. If a procedure fun() is to receive an int, a Single & a double and it is to return a decimal then which of the following is the correct way of defining this procedure?

    • Options
    • A.
      fun(int i, Single j, double k) decimal 
      { ... }
    • B.
      static decimal fun(int i, Single j, double k) 
      { ... }
    • C.
      fun(int i, Single j, double k) 
      {
          ...
          return decimal; 
      }
    • D.
      static decimal fun(int i, Single j, double k) decimal 
      { ... }
    • E. A procedure can never return a value.
    • Discuss
    • 10. Which of the following is the incorrect form of Decision Control instruction?

    • Options
    • A.
      if (Condition1) 
      {// Some statement}
    • B.
      if (Condition1) {// Some statement} 
      else {// Some statement}
    • C.
      if (Condition1) {// Some statement} 
      else {// Some statement} 
      else if ( Condition2){//Some statement}
    • D.
      if ( Condition1 ) {// Some statement} 
      else if ( Condition2 ) {// Some statement} 
      else {// Some statement}
    • E.
      if ( Condition1 ) {// Some statement} 
      else if ( Condition2 ) {// Some statement} 
      else if ( Condition3 ) {// Some statement} 
      else {// Some statement}
    • Discuss


    Comments

    There are no comments.

Enter a new Comment