Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

C# MCQ Set 1

1. Which statement correctly defines Interfaces in C#.NET?
a) Interfaces cannot be inherited
b) Interfaces consists of data static in nature and static methods
c) Interfaces consists of only method declaration
d) None of the mentioned

View Answer

Answer: d [Reason:] Leaving all options only option ‘a’ is correct as interfaces can be inherited i.e inheritance can be performed in csharp .net.

2. Which of the following cannot be used to declare an interface correctly?
a) Properties
b) Methods
c) Structures
d) Events

View Answer

Answer: c [Reason:] None.

3. A class consists of two interfaces with each interface consisting of three methods.The class had no instance data. Which of the following indicates the correct size of object created from this class?
a) 12 bytes
b) 16 bytes
c) 0 bytes
d) 24 bytes

View Answer

Answer: d [Reason:] None.

4. Which of the following statements correctly define about the implementation of interface?
a) The calls to implementation of interface methods are routed through a method table
b) A class which implements an interface can explicitly implement members of that interface
c) One interface can be implemented in another interface
d) None of the mentioned

View Answer

Answer: a [Reason:] None.

5. Select the correct statement among the given statements?
a) One class could implement only one interface
b) Properties could be declared inside an interface
c) Interfaces cannot be inherited
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

6. Which keyword is used for correct implementation of an interface in C#.NET?
a) interface
b) Interface
c) intf
d) Intf

View Answer

Answer: a [Reason:] None.

7. Choose the statements which makes interface different from classes?
a) Unlike classes, interfaces consists of only declaration but not implementation
b) Interfaces cannot be used directly like classes to create new objects
c) Interfaces consists of declaration of methods,properties events and type definitions
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

8. Which of the following is the correct way of implementing an interface addition by class maths?
a) class maths : addition {}
b) class maths implements addition {}
c) class maths imports addition {}
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

9. Does C#.NET support partial implementation of interfaces?
a) True
b) False
c) Can’t Say
d) None of the mentioned

View Answer

Answer: b [Reason:] Interface is a behaviour. It represents a protocol or a contract of sorts.Hence, it is impossible to implement an interface partially.

10. Select the correct implementation of the interface which is mentioned below.

  1. interface a1
  2. {
  3.     int fun(int i);
  4. }

a)

  1.  class a
  2.  {
  3.      int fun(int i) as a1.fun
  4.      {
  5.      }
  6.  }

b)

  1. class a: implements a1
  2. {
  3.     int fun(int i)
  4.     {
  5.     }
  6. }

c)

  1.  class a: a1
  2.  {
  3.      int a1.fun(int i)
  4.      {
  5.      }
  6.  }

d) None of the mentioned

View Answer

Answer: c [Reason:] None.

11. Which of these can be used to fully abstract a class from its implementation?
a) Objects
b) Packages
c) Interfaces
d) None of the Mentioned

View Answer

Answer: c [Reason:] None.

12. Access specifiers which can be used for an interface are?
a) Public
b) Protected
c) Private
d) All of the mentioned

View Answer

Answer: a [Reason:] Access specifier of an interface is either public or none.When no access specifier is specified then only default access specifier is used due to which interface is available only to other members of the package in which it is declared, when declared public it can be used by any code declared anywhere in the class area.

C# MCQ Set 2

1. Select output for the following set of code.

  1.  static void Main(string[] args)
  2.  {
  3.      int a = 5;
  4.      int b = 10;
  5.      int c;
  6.      Console.WriteLine(c = ++ a + b ++);
  7.      Console.WriteLine(b);
  8.      Console.ReadLine();
  9.  }

a) 11, 10
b) 16, 10
c) 16, 11
d) 15, 11

View Answer

Answer: c [Reason:] c = 6 + 10 = 16 and b =11 as we know ++operator increments and then executes similarly operator++ executes and then increments. Output:16,11

2. Storage location used by computer memory to store data for usage by an application is ?
a) Pointers
b) Constants
c) Variable
d) None of the mentioned

View Answer

Answer: c [Reason:] ‘Variables’ are essential locations in memory of computer that are reserved for storing data used by an application. Each variable is given a name by programmer and hence assigned a value .The name assigned to variable then used in C# code to access value assigned to variable.

3. DIFFERENCE BETWEEN KEYWORDS ‘VAR’ AND ‘DYNAMIC’ ?
a) ‘Var’ is introduced in C# (3.0) and ‘Dynamic’ is introduced in C# (4.0)
b) ‘Var’ is a type of variable where declaration is done at compile time by compiler while ‘Dynamic’ declaration is achieved at runtime by compiler
c) For ‘Var’ Error is caught at compile time and for ‘Dynamic’ Error is caught at runtime
d) All of the mentioned

View Answer

Answer: d

4. Are the given codes :

  1.  1. Myclass class;
  2.     Myclass class2 = null;
  1.  2. int i;
  2.     int j = 0;

a) True for (1);False for (2)
b) True for (2);False for (1)
c) Both (1) and (2) are equivalents
d) Both (1) and (2) are not equivalents

View Answer

Answer: c. [Reason:] When we create a type in ‘C#’, It automatically gets filled with padded zeroes. For the case of class (reference types) this equates to a null pointer. Hence, for code 1) Both variable values are equivalent to each other.Similarly, for code 2) i.e for value type (including int/float/double etc.), the type is passed with zeroes.Hence, they are equivalent.

5. What is the output of following set of code ?

  1.   int a,b;
  2.   a = (b = 10) + 5;

a) b = 10, a = 5
b) b = 15, a = 5
c) a = 15, b = 10
d) a = 10, b = 10

View Answer

Answer: c [Reason:] b is assigned 10 and after that its value is added with 5 and then saved in a, so a will be 15.

6. What will be output of the following conversion ?

  1.  static void Main(string[] args)
  2.  {
  3.      char a = 'A';
  4.      string b = "a";
  5.      Console.WriteLine(Convert.ToInt32(a));
  6.      Console.WriteLine(Convert.ToInt32(Convert.Tochar(b)));
  7.      Console.ReadLine();
  8.  }

a) 1, 97
b) 65, 97
c) 65, 97
d) 97, 1

View Answer

Answer: c [Reason:] ASCII value of character ‘a’ is 65 and ASCII value of string “a” is 97. Output: 65,97

7. Select output of the given set of Code :

  1. static void Main(string[] args)
  2. {
  3.     String name = "Dr.Gupta";
  4.     Console.WriteLine("Good Morning" + name);
  5. }

a) Dr.Gupta
b) Good Morning
c) Good Morning Dr.Gupta
d) Good Morning name

View Answer

Answer: c. [Reason:] How to intialize a string variable and concatenate string using ‘+’ operator. Output:Good Morning Dr.Gupta.

8. Select output for the following set of code.

  1.  static void Main(string[] args)
  2.  {
  3.      int a = 5;
  4.      int b = 10;
  5.      int c;
  6.      Console.WriteLine(c = a-- - ++b);
  7.      Console.WriteLine(b);
  8.      Console.ReadLine();
  9.  }

a) -7, 10
b) -5, 11
c) -6, 11
d) 15, 11

View Answer

Answer: c [Reason:] None. Output: -6,11.

9. Select output for the following set of code .

  1.  static void Main(string[] args)
  2.  {
  3.      const int a = 5;
  4.      const int b = 6;
  5.      for (int i = 1; i <= 5; i++)
  6.      {
  7.          a = a * i;
  8.          b = b * i;
  9.      }
  10.      Console.WriteLine(a);
  11.      Console.WriteLine(b);
  12.      Console.ReadLine();
  13.  }

a) 600, 720
b) Compile time error.
c) 25, 30
d) 5, 6

View Answer

Answer: b [Reason:] The left hand side of an assignment must be a variable,property or indexer i.e for both ‘a’ and ‘b’

10. Select output for the following set of code.

  1.  static void Main(string[] args)
  2.  {
  3.      string Name = "He is playing in a ground.";
  4.      char[] characters = Name.ToCharArray();
  5.      StringBuilder sb = new StringBuilder();
  6.      for (int i = Name.Length - 1; i >= 0; --i)
  7.      {
  8.          sb.Append(characters[i]);
  9.      }
  10.      Console.Write(sb.ToString());
  11.      Console.ReadLine(); 
  12.  }

a) He is playing in a grou
b) .ground a in playing is He
c) .dnuorg a ni gniyalp si eH
d) He playing a

View Answer

Answer: c [Reason:] Reversal of array of strings character by character. Output: .dnuorg a ni gniyalp si eH

C# MCQ Set 3

1. Choose the correct statement among the followings?
a) Indexers are location indicators
b) Indexers are used to access class objects
c) Indexer is a form of property and works in the same way as a property
d) All of the mentioned

View Answer

Answer: d [Reason:] By definition.

2. Choose the keyword which declares the indexer?
a) base
b) this
c) super
d) extract

View Answer

Answer: b [Reason:] The indexer is declared using the name this.

3. Choose the operator/operators which is/are not used to access the [] operator in indexers?
a) get
b) set
c) access
d) all of the mentioned

View Answer

Answer: c [Reason:] The indexer is implemented through the get and set accessors for the [] operator as:

  public double this[int idx]
              {
                 get
                 {
                   if()
                  {
                  }
                 else
                 {
                    return([idx]);
                 }
 
              }
                 set
                 {
                      array[idx];
 
                 }
           }

4. Choose the correct statement among the following?
a) A property can be a static member whereas an indexer is always an instance member
b) A get accessor of a property corresponds to a method with no parameters whereas get accessor of an indexer corresponds to a method with the same formal parameters lists as the indexer
c) It is an error for indexer to declare a local variable with the same name as indexer parameters
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

5. For a class student consisting of indexer,which among the following declaration of indexers runs the code successfully ?
student a = new student();
a[1,2] = 20;

a) class student
{
int[,] p = new int[6, 6];
public property WriteOnly int this[int i, int j]
{
set
{
a[i, j] = value;
}
}
}
b) class student
{
int[,] a = new int[6, 6];
public int this[int i, int j]
{
set
{
a[i, j] = value;
}
}
} 
c) class student
{
int[,] a = new int[6, 6];
public int property WriteOnly
{
set
{
a[i, j] = value;
}
}  
}
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

6. Which among the following are the advantages of using indexers?
a) To use collection of items at a large scale we make use of indexers as they utilize objects of class that represent the collection as an array
b) Indexers are also convenient as they can also make use of different types of indexers like int, string etc
c) An indexer allows an object to be indexed such as an array
d) All of the mentioned

View Answer

Answer: d [Reason:] Indexers provides a view at large scale to visualize a collection of items as an array.It is really easy to use the object of the class that represents a collection as if it is an array.Hence, indexed properties allow us to represent such a view. Indexers can also use different types of indexes like int , string etc. Use int as an index where sequential access to a collection is desired.When symbolic access is needed,use string as an index.

7. Choose the correct statement about properties describing the indexers?
a) No need to use the name of the property while using an indexed property
b) An indexer property should accept at least one argument
c) Indexers can be overloaded
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

8. Choose the correct alternative that utilizes the indexed property such that a group named class has indexed property which stores or retrieves value to/from an array of 5 numbers?
a) group[3] = 34;
b) group g = group();
c) Console.WriteLine(group[3]);
d) group g = new group();
Console.WriteLine(g[3]);

View Answer

Answer: d [Reason:] None.

9. Choose the correct option among the following indexers which correctly allows to index in same way as an array?
a) A class
b) An interface
c) A function
d) A property

View Answer

Answer: a [Reason:] None.

10. Choose the output for the given set of code?

  1.  class list
  2.  {
  3.      ArrayList array = new ArrayList();
  4.      public object this[int index]
  5.      {
  6.          get
  7.          {
  8.              if (index < 0 || index >= array.Count)
  9.              {
  10.                  return null;
  11.              }
  12.              else
  13.              {
  14.                  return (array[index]);
  15.              }
  16.          }
  17.          set
  18.          {
  19.              array[index] = value;
  20.          }
  21.      }
  22.      public int Count 
  23.     { 
  24.         get;
  25.         set; 
  26.     }
  27. }
  28. class Program
  29. {
  30.     static void Main(string[] args)
  31.     {
  32.         list list1 = new list();
  33.         list1[0] = "123";
  34.         list1[1] = " abc ";
  35.         list1[2] = "xyz";
  36.         for (int i = 0; i<=list1.Count; i++)
  37.         Console.WriteLine(list1[i]);
  38.         Console.ReadLine();
  39.     }
  40. }

a) Compile time error
b) Run time error
c) 123, abc, xyz
d) 0

View Answer

Answer: b [Reason:] Index out of range which arises only when index is non negative or less than the collection of size.

C# MCQ Set 4

1. Choose the wrong statement about the properties used in C#.NET?
a) Each property consists of accessor as get and set
b) A property cannot be either read or write only
c) Properties can be used to store and retrieve values to and from the data members of a class
d) Properties are like actual methods which work like data members

View Answer

Answer: a [Reason:] None.

2. Choose the statements which makes use of essential properties rather than making data member public in C#.NET?
a) Properties have their own access levels like private, public, protected etc. which allows it to have better control about managing read and write properties
b) Properties give us control about what values may be assigned to a member variables of a class they represent
c) Properties consist of set accessor inside which we can validate the value before assigning it to the data variable
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

3. Where the properties can be declared?
a) Class
b) Struct
c) Interface
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

4. Select the modifiers which can be used with the properties?
a) Private
b) Public
c) Protected Internal
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

5. Choose the correct statements about write-only properties in C#.NET?
a) Properties which can only be set
b) Properties once set and hence values cannot be read back in nature
c) Useful for usage in classes which store sensitive information like password of a user
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

6. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the statement b.sum = 10 to fail.Which of the follwing is the correct
solution to ensure this functionality?
a) Declare sum property with both get and set accessors
b) Declare sum property with only get accessor
c) Declare sum property with get, set and normal accessors
d) None of the mentioned

View Answer

Answer: c [Reason:] None.

7. Consider a class maths and we had a property called as sum.b which is the reference to a maths object and we want the statement Console.WriteLine(b.sum)to fail.Which among the following is the correct solution to ensure this functionality?
a) Declares sum property with only get accessor
b) Declares sum property with only set accessor
c) Declares sum property with both set and get accessor
d) Declares sum property with both set, get and normal accessor

View Answer

Answer: b [Reason:] None.

8. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the code below to work.Which is the correct solution to ensure this functionality?
b.maths = 10;
Console.WriteLine(b.maths);
a) Declare maths property with get and set accessors
b) Declare maths property with only get accessors
c) Declare maths property with only set accessors
d) Declare maths property with only get, set and normal accessors

View Answer

Answer: a [Reason:] None.

9. If math class had add property with get and set accessors, then which of the following statements will work correctly?
a) math.add = 20;
b) math m = new math();
m.add = 10;
c) Console.WriteLine(math.add);
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

10. If the math class had add property with get accessors then which of the following statements will work correctly?
a) math m = new math();
m.add = 10;
b) math m = new math();
m.add = m.add + 20;
c) math m = new math();
int i;
i = m.add;
d) math.add = 20;

View Answer

Answer: c [Reason:] None.

C# MCQ Set 5

1. Select the namespace on which the stream classes are defined?
a) System.IO
b) System.Input
c) System.Output
d) All of the mentioned

View Answer

Answer: a [Reason:] The core stream classes are defined within the System.IO namespace. To use these classes, you will usually include the following statement near the top of your program: using System.IO;

2. Choose the class on which all stream classes are defined?
a) System.IO.stream
b) Sytem.Input.stream
c) System.Output.stream
d) All of the mentioned

View Answer

Answer: a [Reason:] The core stream class is System.IO.Stream. Stream represents a byte stream and is a base class for all other stream classes. It is also abstract, which means that you cannot instantiate a Stream object. Stream defines a set of standard stream operations.

3. Choose the stream class method which is used to close the connection:
a) close()
b) static close()
c) void close()
d) none of the mentioned

View Answer

Answer: c [Reason:] void close() closes the stream.

4. The method used to write a single byte to an output stream?
a) void WriteByte(byte value)
b) int Write(byte[] buffer ,int offset ,int count)
c) write()
d) none of the mentioned

View Answer

Answer: a [Reason:] Writes a single byte to an output stream.

5. Select the method which writes the contents of the stream to the physical device.
a) fflush()
b) void fflush()
c) void Flush()
d) flush()

View Answer

Answer: c [Reason:] The method used to write the contents of the stream to the physical device.

6. Select the method which returns the number of bytes from the array buffer:
a) void WriteByte(byte value)
b) int Write(byte[] buffer ,int offset ,int count)
c) write()
d) none of the mentioned

View Answer

Answer: b [Reason:] Writes a subrange of count bytes from the array buffer,beginning at buffer[offset], returning the number of bytes written.

7. Name the method which returns integer as -1 when the end of file is encountered.
a) int read()
b) int ReadByte()
c) void readbyte()
d) none of the mentioned

View Answer

Answer: b [Reason:] Returns an integer representation of the next available byte of input. Returns –1 when the end of the file is encountered.

8. Select the statements which define the stream.
a) A stream is an abstraction that produces or consumes information
b) A stream is linked to a physical device by the I/0 system
c) C# programs perform I/O through streams
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

9. Select the action of the method long seek()?
a) Attempts to readup to count bytes into buffer starting at buffer[offset].
b) Writes a single byte to an output stream
c) Sets the current position in the stream to the specified offset from specified origin and hence returns the new position
d) None of the mentioned

View Answer

Answer: c [Reason:] long Seek(long offset, SeekOrigin origin) Sets the current position in the stream to the specified offset from the specified origin. It returns the new position.

10. Which among the following attempts to read up to count bytes into buffer starting at buffer[offset], returning the number of bytes successfully read?
a) int ReadByte()
b) int Read(byte[] buffer ,int offset ,int count)
c) Void WriteByte(byte value)
d) None of the mentioned

View Answer

Answer: b [Reason:] None.