C# Set 3 (30 mcqs)

1. What is output of following set of code ?
1.static void Main(string[] args)
2.{
3.    int i, j;
4.    int[, ] arr = new int[ 3, 3];
5.    for (i = 0; i < 3; ++i)
6.    {
7.        for (j = 0; j < 3; ++j)
8.        {
9.            arr[i, j] = i * 2 + i * 2;
10.            Console.WriteLine(arr[i, j]);
11.        }
12.        Console.ReadLine();
13.    }
14.}
a) 0,0,0 4,4,4 8,8,8
b) 4,4,4 8,8,8 12,12,12
c) 8,8,8 12,12,12 16,16,16
d) 0,0,0 1,1,1, 2,2,2

2. What is output for following set of code?
1. static void Main(string[] args)
2. {
3.     char A = ‘K’;
4.     char B = Convert.ToChar(76);
5.     A++;
6.     B++;
7.     Console.WriteLine(A+ ”  ” +B);
8.     Console.ReadLine();
9. }
a) M L
b) U L
c) L M
d) A B

3. Complete following set of code with “foreach condition”:
1.int[][]a = new int[2][];
2.a[0] = new int[3]{3, 4, 2};
3.a[1] = new int[2]{8, 5};
4.foreach( int[]i in a)
5.{
6./* add for loop */
7.console.write( j+ ” “);
8.console.writeline();
9.}
(a) foreach (int j = 1;(j(<)(a(0).GetUpperBound)); (j++));
(b) foreach (int j = 1;(j(<)(a.GetUpperBound(0))); (j++));
(c) foreach (int j in a.Length);
(d) foreach (int j in i);

4. What is output for following set of code ?
1.static void Main(string[] args)
2.{
3.    double a = 345.09;
4.    byte c = (byte) a;
5.    Console.WriteLine(c);
6.    Console.ReadLine();
7.}
a) 98
b) 89
c) 88
d) 84

5. Which statement is correct about following c#.NET code ?
int[] a= {11, 3, 5, 9, 6};
a)’a’ is reference to the array created on stack
b)’a’ is a reference to an object created on stack
c)’a’ is a reference to an object of a class that compiler drives from ‘System.Array’ class
d) None of the mentioned

6. What is advantage of using 2D jagged array over 2D rectangular array?
a) Easy intialization of elements
b) Allow unlimited elements as well as also rows which had ’0′ or are empty in nature
c) All of the mentioned
d) None of the mentioned

7. Which statement is correct about following set of code ?
int[, ]a={{5, 4, 3},{9, 2, 6}};
a)’a’ represents 1-D array of 5 integers
b) a.GetUpperBound(0) gives 9
c)’a’ represents rectangular array of 2 columns and 3 arrays
d) a.GetUpperBound(1) gives 2

8. What is output of following set of code?
1.static void Main(string[] args)
2.{
3.    Program p = new Program();
4.    p.display(2, 3, 8);
5.    int []a = { 2, 56, 78, 66 };
6.    Console.WriteLine(“example of array”);
7.    Console.WriteLine(“elements added are”);
8.    p.display(a);
9.    Console.ReadLine();
10.}
11.public void display(params int[] b)
12.{
13.    foreach (int i in b)
14.    {
15.        Console.WriteLine(“ARRAY IS HAVING:{0}”, i);
16.    }
17.}
a) Compile time error
b) Run time error
c) Code runs successfully but prints nothing
d) Code runs successfully and prints given on console

9. Which is correct way of defining and initialize an array of 3 integers?
a) int[] a={78, 9, 54};
b) int[] a;
a = new int[3];
a[1] = 78;
a[2] = 9;
a[3] = 54;
c) int[] a;
a = new int{78, 9, 54};
d) int[] a;
a = new int[3]{78, 9, 54};

10. Choose selective difference between array in c# and array in other programming languages.
a) Declaring array in C# the square bracket([]) comes after the type but not after identifier
b) It is not necessary to declare size of an array with it’s type
c) No, difference between declartion of array in c# as well as as in other programming languages
d) All of the above mentioned
e) None of above mentioned

11. Which keyword is used to declare a base class method while performing overidding of base class methods?
a) this
b) virtual
c) override
d) extend

12. The process of defining a method in subclass having same name & type signature as a method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned

13. Which of given modifiers can be used to prevent Method overriding?
a) Static
b) Constant
c) Sealed
d) final

14. Select the correct statement from the following?
a) Static methods can be a virtual method
b) Abstract methods can be a virtual method
c) When overriding a method,the names and types signatures of the override method must be the same as the virtual method that is being overriden
d) We can override virtual as well as non virtual methods

15. Which of the following can be used to declared as a virtual in a class?
a) Methods
b) Properties
c) Events
d) Fields

16. What will be the output for given set of code?
1. class A
2. {
3.     public int i;
4.     public void display()
5.     {
6.         Console.WriteLine(i);
7.     }
8. }
9. class B: A
10. {
11.     public int j;
12.     public void display()
13.     {
14.         Console.WriteLine(j);
15.     }
16. }
17. class Program
18. {
19.     static void Main(string[] args)
20.     {
21.         B obj = new B();
22.         obj.i = 1;
23.         obj.j = 2;
24.         obj.display();
25.         Console.ReadLine();
26.     }
27. }
a) 0
b) 2
c) 1
d) Compile time error

17. What will be the output for given set of code?
1. class A
2. {
3.     public virtual void display()
4.     {
5.         Console.WriteLine(“A”);
6.     }
7. }
8. class B: A
9. {
10.    public override void display()
11.    {
12.        Console.WriteLine(” B “);
13.    }
14. }
15.class Program
16.{
17.    static void Main(string[] args)
18.    {
19.        A obj1 = new A();
20.        B obj2 = new B();
21.        A r;
22.        r = obj1;
23.        r.display();
24.        r = obj2;
25.        r.display();
26.        Console.ReadLine();
27.    }
28.}
a) A, A
b) B, B
c) Compile time error
d) A, B

18. The modifier used to hide the base class methods?
a) Virtual
b) New
c) Override
d) Sealed

19. To override a method in subclass in baseclass method should be defined as?
a) virtual
b) abstract
c) Static
d) Override

20. What will be the output for given set of code?
1. class a
2. {
3.     public  void fun()
4.     {
5.         Console.WriteLine(“base method”);
6.     }
7. }
8. class b: a
9. {
10.     public new void fun()
11.     {
12.         Console.WriteLine(” derived method “);
13.     }
14. }
15. class Program
16. {
17.     static void Main(string[] args)
18.     {
19.         b k = new b();
20.         k.fun();
21.         Console.ReadLine();
22.     }
23. }
a) base method
b) derived method
c) Code run successfully print nothing
d) Compile time error

21. What are strings in C#?
a) a sequence of characters
b) array of characters
c) objects of built in data type
d) a reference type

22. Select the namespace in which string class is built?
a) System.Text
b) System.Net
c) System.IO
d) None of the mentioned

23. Select the interfaces defined by the string class?
a) IComparable
b) IComparable
c) ICloneable
d) IEnumerable

24. Choose the constructor type used to built strings from character array:
a) public String(char[ ] value)
b) public String(char[ ] value, int startIndex, int length)
c) public String(char[ ])
d) All of the mentioned

25. Select the operators used for checking the equality in strings:
a) !=
b) ==
c) <
d) >=

26. What does the given code set specifies?
1.public static int Compare(string strA, string strB)
a) Comparison is case and culture sensitive
b) Two strings A and B are compared with each other
c) Output is : >0 for (A > B), <0 for (A < B) else ‘0’ for(A=B)
d) All of the mentioned

27. Select the output for given set of code:
1.static void Main(string[] args)
2.{
3.    string s1 = “Hello” + “c” + “Sharp”;
4.    Console.WriteLine(s1);
5.    Console.ReadLine();
6.}
a) Hello c Sharp
b) HellocSharp
c) Compile time error
d) Hello

28. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||

29. What does the given code set specifies?
1.public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)
a) Comparison begins at strA[indexA] and strB[indexB] and runs for length of characters
b) Returns output > 0 for for strA > strB else < 0 for strA < strB else if strA = str B output is 0
c) Comparison is culture sensitive and if ignore case is true, comparison ignores case differences
d) All of the mentioned

30. Which string operation does the below mentioned method defines?
1.public static string Concat(string str0, string str1)
a) method returns a string
b) string str1 is concatenated to the end of str0
c) can be used to concatenate any number of strings
d) None of the mentioned

Answers

1-a 2-c 3-d 4-b 5-c
6-b 7-c,d 8-d 9-a,d 10-a,b
11-b 12-b 13-c 14-c 15-a,b,c
16-b 17-d 18-b 19-a,b,d 20-b
21-c,d 22-a 23-a,b,c,d 24-a,b 25-a,b
26-d 27-a 28-a 29-d 30- a,b,c
Spread the love

Leave a Comment

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