Uploaded by Kgothatso Selepe

PROGRAMMING 741 C# CA2

advertisement
Topic: 4
1. What is the output of the following set of code ?
static void Main(string[] args)
{
int i, j;
int[, ] arr = new int[ 3, 3];
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
{
arr[i, j] = i * 2 + i * 2;
Console.WriteLine(arr[i, j]);
}
Console.ReadLine();
}
}
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
Answer : a.
2. What is the output for the following set of code?
static void Main(string[] args)
{
char A = 'K';
char B = Convert.ToChar(76);
A++;
B++;
Console.WriteLine(A+ " " +B);
Console.ReadLine();
}
a) M L
b) U L
c) L M
d) A B
Answer :c.
3. Complete the following set of code with “foreach condition”:
int[][]a = new int[2][];
a[0] = new int[3]{3, 4, 2};
a[1] = new int[2]{8, 5};
foreach( int[]i in a)
{
/* add for loop */
console.write( j+ " ");
console.writeline();
}
(a) foreach (int j = 1;(j(<)(a(0).GetUpperBound)); (j++));
(b) (b) foreach (int j = 1;(j(<)(a.GetUpperBound(0))); (j++));
(c) (c) foreach (int j in a.Length);
(d) (d) foreach (int j in i);
Answer :d
4. What is the output for the following set of code ?
static void Main(string[] args)
{
double a = 345.09;
byte c = (byte) a;
Console.WriteLine(c);
Console.ReadLine();
}
a) 98
b) 89
c) 88
d) 84
Answer :b
5. Which statement is correct about following c#.NET code ?
int[] a= {11, 3, 5, 9, 6};
(a) ’a’ is a 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
Answer :c.
6.
a)
b)
c)
d)
What is the advantage of using 2D jagged array over 2D rectangular array?
Easy initialization of elements
Allows unlimited elements as well as rows which had ‘0’ or are empty in nature
All of the mentioned
None of the mentioned
Answer: b.
7. Which statement is correct about following set of code ?
int[, ]a={{5, 4, 3},{9, 2, 6}};
a) a)’a’ represents 1-D array of 5 integers
b) a.GetUpperBound(0) gives 9
c) c)’a’ represents rectangular array of 2 columns and 3 arrays
d) a.GetUpperBound(1) gives 1
Answer: c
8. What is output of the following set of code?
static void Main(string[] args)
{
Program p = new Program();
p.display(2, 3, 8);
int []a = { 2, 56, 78, 66 };
Console.WriteLine("example of array");
Console.WriteLine("elements added are");
p.display(a);
Console.ReadLine();
}
public void display(params int[] b)
{
foreach (int i in b)
{
Console.WriteLine("ARRAY IS HAVING:{0}", i);
}
}
a)
b)
c)
d)
Compile time error
Run time error
Code runs successfully but prints nothing
Code runs successfully and prints given on console
Answer :d
9. Which is the correct way of defining and initializing 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
a = new int[3]{78, 9, 54};
Answer: a
10. Choose selective differences between an 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 its type
c) No difference between declaration of array in c# as well as as in other programming
languages
d) All of the above mentioned
Answer : a
11. Which of the following string() method are used to compare two strings with each other?
a) CopyTo()
b) Copy()
c) Compare()
d) CompareTo()
Answer: b
12.
a)
b)
c)
Choose the base class for string() method :
System.Array
System.char
System.String
d) None of the mentioned
Answer: c
13. What is output for the following set of code:
static void Main(string[] args)
{
string s1 = " Cshr ";
string s2 = s1.Insert(3 , " a ");
string s3 = s2.Insert(5 , " p ");
for (int i = 0;i < s3.Length; i++)
Console.WriteLine(s3[i]);
Console.ReadLine();
}
a) Cshar
b) CsharP
c) Csharp
d) Cshrap
Answer: c
14. Which of the following statement is correct about a string in C#.NET?
a) The System.Array class is used to represent a string
b) A string has a zero-based index
c) A number cannot be represented in the form of a string
d) A string is mutable because it can be modified once it has been created
Answer: b
15. What is output for the following set of code?
static void Main(string[] args)
{
string s1 = "Hello";
string s2 = "hello";
if (s1 == s2)
Console.WriteLine("Equal");
else
Console.WriteLine("Unequal");
if (s1.Equals (s2))
Console.WriteLine("Equal");
else
Console.WriteLine("Unequal");
Console.ReadLine();
}
a) Equal
Unequal
b) Unequal
Equal
c) Equal
Equal
d) Unequal
Unequal
Answer: d
16. Choose Output for the following set of code :
static void Main(string[] args)
{
string s1 = "Hello" + " I " + "Love" + " ComputerScience ";
Console.WriteLine(s1);
Console.ReadLine();
}
a) HelloILoveComputerScience
b) Hello I Love ComputerScience
c) Compile time error
d) Hello
Answer: b
17. Correct way to find if contents of two strings are equal ?
a) if (s1 = s2)
b) if (s1 == s2)
c) if (strcmp= (s1 ,s2))
d) if ( s1 is s2)
Answer: b
18. Which of the following statements are correct?
a) String is value type
b) String literals can contain any character literal including escape sequences
c) The equality operators are defined to compare values of string objects as well as references
d) All of the mentioned
Answer: b
19. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||
Answer: a
20. The Method use to remove white space from string?
a) Split()
b) Substring()
c) Trim()
d) TrimStart()
Answer: c
21. What is the String in C# meant for?
a) Variable
b) Character Array
c) Object
d) Class
Answer: c
22. What does the term ‘immutable’ means in term of string objects?
a) We can modify characters included in the string
b) We cannot modify characters contained in the string
c) We cannot perform various operation of comparison,inserting,appending etc
d) None of the mentioned
Answer: b
23. To perform comparison operation on strings supported operations are :
a) Compare().
b) Equals(“”).
c) Assignment ‘=%=’ operator.
d) None of the mentioned.
Answer: a
24. What will be output of the following set of code :
static void Main(string[] args)
{
string s1 = "Hello I Love Csharp ";
Console.WriteLine(Convert.ToChar( (s1.IndexOf('I') - s1.IndexOf('l')) * s1.IndexOf('p'));
Console.ReadLine();
}
a) I
b) Hello I
c) Love
d) H
Answer: d
25. Correct way to convert a string to uppercase using string class method()?
a) Upper()
b) ToUpper()
c) Object.ToUpper()
d) None of the mentioned
Answer: c
26. 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();
}
a) True True
b) False False
c) True 0
d) False 1
Answer: c
27. What would be the output for the code below?
static void Main(string[] args)
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
Console.WriteLine(obj + " " + obj1);
string s = obj + " " + obj1;
Console.WriteLine(s.Length);
Console.ReadLine();
}
a) hello world
10
b) hello world
6
c) hello world
11
d) hello world
5
Answer: c
28. What is output for the following set of Code?
static void Main(string[] args)
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
string s = obj+" "+obj1;
Console.WriteLine(s.IndexOf('r'));
Console.ReadLine();
}
a) 7
b) 8
c) 9
d) 10
Answer: b
29. What is output for the set of code?
static void Main(string[] args)
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
string s = obj + " " + obj1;
Console.WriteLine(s.Substring(6 ,5));
Console.ReadLine();
}
a) hello
b) orld
c) world
d) o world
Answer: c
30. What will be the output for the set of given code?
static void Main(string[] args)
{
String obj = "hello";
String obj1 = "worn";
String obj2 = obj;
Console.WriteLine(obj + " " + (obj1.Replace('w' ,'c')));
Console.ReadLine();
}
a) hello hello
b) hello worn
c) hello corn
d) hello
Answer: c
31. Which of these methods of class String is used to compare two String objects for their
equality?
a) equals()
b) Equals()
c) isequal()
d) Isequal()
Answer: a
32. Which of these methods is used to compare two strings such that after comparison output
returns different integer values as ( 0 for false, 1 for true)?
a) Equals ()
b) == operator
c) Compare()
d) None of the mentioned
Answer: c
33. Which of these methods of class String is used to check whether a substring exists at the
beginning of the particular string?
a) StartsWith()
b) EndsWith()
c) Starts()
d) ends()
Answer: a
34. 4. Which of these methods returns the string such that some characters which are specified
to be removed from the end of strings are removed from string by mentioning the number
of characters to be removed?
a) Trim()
b) Remove()
c) TrimEnd()
d) Split()
Answer: a
35. What is the value returned by function compareTo() if the invoking string is less than the
string compared?
a) zero
b) value less than zero
c) value greater than zero
d) None of the mentioned
Answer: b
36. Which of these data type values is returned by equals() method of String class?
a) char
b) int
c) boolean
d) All of the mentioned
View Answer
Answer: c
37. What is output of the given set of Code?
class Program
{
static void Main(string[] args)
{
String c = "i love Csharp";
bool a;
a = c.StartsWith("I");
Console.WriteLine(a);
Console.ReadLine();
}
}
a) true
b) false
c) 0
d) 1
Answer: b
What is the output of the given set of Code?
class Program
{
static void Main(string[] args)
{
String s1 = "I love You";
String s2 = s1;
Console.WriteLine((s1 == s2) + " " + s1.Equals(s2));
Console.ReadLine();
}
}
a) true true
b) false false
c) true false
d) false true
Answer: a
38. What is output of the given set of Code?
class Program
{
static void Main(string[] args)
{
String []chars = {"z", "x", "y", "z", "y"};
for (int i = 0; i < chars.Length; ++i)
for (int j = i + 1; j < chars.Length; ++j)
if(chars[i].CompareTo(chars[j]) == 0)
Console.WriteLine(chars[j]);
Console.ReadLine();
}
}
a) zx
b) xy
c) zy
d) yz
Answer: c
39. What will be the output for the given set of code ?
String a = "Csharp";
String b = "CSHARP";
int c;
c = a.CompareTo(b);
Console.WriteLine(c);
a) 0
b) 1
c) -2
d) -1
Answer: d
40. Which of these methods of class String is used to separate a substring from a String object?
a) substring()
b) Substring()
c) SubString()
d) None of the mentioned
Answer: b
41. What will be the output for the given set of code?
static void Main(string[] args)
{
String a = "Ilove";
String b = "CSHARP";
b = string.Concat(a, ' ', b);
Console.WriteLine(b);
Console.ReadLine();
}
a) IloveCSHARP
b) I loveCSHARP
c) Ilove
d) Ilove CSHARP
Answer: d
42. Which of these methods of class are used to remove the leading and backward whitespaces?
a) startsWith()
b) trim()
c) Trim()
d) doTrim()
Answer: c
43. What will be the output for the given set of code?
static void Main(string[] args)
{
String a = "Ilove";
String b = "CSHARP";
b = string.Concat(a,' ',b);
string d = b.TrimStart('I', 'l', 'o', 'H');
Console.WriteLine(d);
Console.ReadLine();
}
a) Ilove CSHARP
b) love CSHARP
c) ve CSHARP
d) ve CSARP
Answer: c
44. What will be the output for the given set of code?
static void Main(string[] args)
{
String c = " Hello Computer ";
String a = c.Trim();
Console.WriteLine("\"" + s + "\"");
}
a) ” Hello Computer ”
b) “HelloComputer”
c) “Hello Computer”
d) Hello Computer
Answer: c
45. 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();
}
a) “Hello Bye”
b) “HelloBye”
c) Hello Bye
d) HelloBye
Answer: d
46. What will be the output for the given set of code?
static void Main(string[] args)
{
String c = "Hello";
String a ;
a = c.Replace('l', 'w');
Console.WriteLine(a);
Console.ReadLine();
}
a) Helloll
b) Hewlo
c) Helwo
d) Hewwo
Answer: d
47. Which of the following statements is correct?
a) replace() replace() method replaces last occurrence of a character in invoking strings with
another character
b) replace() method replaces only first occurrence of a character in invoking strings with
another character
c) replace() method replaces all occurrences of one character in invoking strings with another
character
d) None of the mentioned
Answer: c
48. What will be the output of the given code snippet?
static void Main(string[] args)
{
String c = "Hello i love you";
String a ;
a = c.Substring(12, 3);
Console.WriteLine(a);
Console.ReadLine();
}
a) ove
b) you
c) yo
d) love you
49. Which among the following is the correct way to find out the index of second ‘s’ in the string
“She sold her beauty in one night to someone else”?
a) String a = “She sold her beauty in one night to someone else”;
int i;
i = a.SecondIndexOf(“s”);
b) String a = “She sold her beauty in one night to someone else”;
int i, j;
i = a.FirstIndexOf(“s”);
j = a.IndexOf(“s”, i + 1);
c) String a = “She sold her beauty in one night to someone else”;
int i, j;
i = a.IndexOf(“s”);
j = a.IndexOf(“s”, i + 1);
d) None of the mentioned
Answer: c
Explanation : static void Main(string[] args)
{
50. Which of these methods of the class String is used to obtain length of String object?
a) get()
b) Sizeof()
c) lengthof()
d) length()
Answer: d
51. Which of these methods is an alternative to getChars() that stores the characters in an array
of bytes?
a) getBytes()
b) GetByte()
c) giveByte()
d) Give Bytes()
Answer: a
52. Which of these methods can be used to convert all characters in a String into a character
array?
a) CharAt()
b) getChars()
c) TocharArray()
d) All of the mentioned
Answer: c
53. What will be the output of the given code snippet?
static void main(String args[])
{
char chars[] = {'x', 'y', 'z'};
String s = new String(chars);
Console.WriteLine(s);
}
a) x
b) xy
c) z
d) xyz
Answer: d
54. Choose the effective stringBuilder method which helps in producing output for the given
code?
static void Main(string[] args)
{
StringBuilder s = new StringBuilder("object");
s./*______*/("Oriented Language");
Console.WriteLine(s);
Console.ReadLine();
}
Output : objectOriented Language
a) Insert()
b) Add()
c) Append()
d) Join()
Answer: c
55. 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();
}
a) 3 5 7
b) 4 5 6
c) 3 9 6
d) 2 4 6
Answer: c
56. Which of these methods of class String is used to extract all the characters from a String
object?
a) CHARAT()
b) Remove()
c) charAt()
d) Replace()
Answer: b
57. What will be the output of the given code snippet?
static void Main(string[] args)
{
string c = "hello";
string c1 = c.Remove(1);
Console.WriteLine(c1);
}
a) ello
b) h
c) hell
d) None of the mentioned
Answer: b
58. How is a string typically processed?
a) On a character by character basis
b) On a string by string basis
c) Both a & b
d) None of the mentioned
Answer: a
59. How to print \\ on the screen?
a) Console.WriteLine(“\\”);
b) Console.WriteLine(“\\\”);
c) Console.WriteLine(“\\\\”);
d) Console.WriteLine(“\\\\\\”);
Answer: c
60. Which of these is used as a default specifier for a member of the class if no access specifier is
used for it?
a) private
b) public
c) public, within its own class
d) protected
Answer :a
61. Which of these is used to access members of class before the object of that class is created?
a) public
b) private
c) static
d) protected
Answer :c
62. Which of these base classes are accessible to the derived class members?
a) static
b) protected
c) private
d) Shared
Answer :b
63. What is the process by which we can control parts of a program that can access the
members of a class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
Answer :c
64. What will be the output of the following set of code?
class sum
{
public int x;
private int y;
public void math(int a, int b)
{
x = a * 4;
y = b;
}
}
class Program
{
static void Main(string[] args)
{
sum p = new sum();
p.math(12, 30);
Console.WriteLine(p.x + " " + p.y);
Console.ReadLine();
}
}
a) 48, 30
b) 48, 0
c) 0, 0
d) Compile time error
Answer :d
65. 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();
}
}
6, 9
5, 9
9, 10
3, 2
Answer :b
66. What will be the output of the following code?
class math
{
public int a,b;
public math(int i, int j)
{
a = i;
b = j;
}
public void sum(math m)
{
m.a *= 2;
m.b += 2;
}
}
class Program
{
static void Main(string[] args)
{
math t = new math(20, 10);
t.sum(t);
Console.WriteLine(t.a + " " + t.b);
Console.ReadLine();
}
}
a) 10, 20
b) 20, 10
c) 40, 12
d) 5, 40
Answer : c
67. Accessibility modifier defined in a class are?
a) public, private, protected
b) public, internal, protected internal.
c) public, private, internal, protected internal.
d) public, private, protected, internal, protected internal
Answer :d
68. Choose the statements which are true in nature:
a) The base class member functions can access public member functions of derived class
b) An object of a derived class cannot access private member of the base class
c) Private members of the base class cannot be accessed by derived class member functions or
objects of derived class
d) None of the mentioned
Answer : b, c
69. Which of these access specifiers must be used for main() method?
a) private
b) public
c) protected
d) None of the mentioned
Answer :a
70. What is output for the following code snippet?
class Program
{
static void Main(string[] args)
{
int i = 5;
int j;
method1(ref i);
method2(out j);
Console.writeline(i + " " + j);
}
static void method1(ref int x)
{
x = x + x;
}
static void method2(out int x)
{
x = 6;
x = x * x;
}
}
a) 36, 10
b) 10, 36
c) 0, 0
d) 36, 0
Answer :b
71. Statements about ‘ref’ keyword used in C#.NET are?
a) The ref keyword causes arguments to be passed by reference
b) While using ‘ref’ keyword any changes made to the parameter in the method will be
reflected in the variable when control is passed back to the calling method
c) No change is reflected back to variable if any changes are made to the parameter when
control is passed back to calling method
d) Ref usage eliminates overhead of copying large data items
Answer : b
72. What will be the output for the given set of code?
static void main(string[] args)
{
int n = 1;
method(n);
console.Writeline(n);
method1(ref n);
console.Writeline(n);
}
static void method(int num)
{
num += 20;
console.writeline(num);
}
static void method1(ref int num)
{
num += 20;
console.writeline(num);
}
a) 1
1
1
1
b) 21
1
21
21
c) 11
21
21
11
d) 21
1
21
21
Answer :d
73. Which method does following set of code explains?
static void Main(string[] args)
{
int a = 10, b = 20;
method(ref a, ref b);
console.writeline(a + " " + b);
}
static void swap(ref int i, ref int j)
{
int t;
t = i;
i = j;
j = t;
}
a) Call by reference
b) Call by value
c) Output parameter
d) parameter arrays
Answer :a
74. What will be the output for the given set of code?
static void main(string[] args)
{
int []arr = new int[]{ 1, 2, 3, 4, 5};
fun (ref arr);
for (int i = 0; i < arr.Length ; i++)
Console.WriteLine( arr[i] + " ");
}
static void fun(ref int[]a)
{
a = new int[6];
a[3] = 32;
a[1] = 24;
}
a) 0, 0, 32, 0, 0, 0
b) 0, 24, 0, 32, 0, 0
c) 24, 0, 32, 0, 0, 0
d) 0, 0, 32, 0, 0, 0
Answer :b
75. 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;
}
a) 4490
b) 5040
c) 5400
d) 3500
Answer :b
76. What will be the output of the given set of code?
static void Main(string[] args)
{
int a = 5;
int b = 0, c = 0;
method (a, ref b, ref c);
Console.WriteLine(b + " " + c);
Console.ReadLine();
}
static int method(int x, int p, ref int k)
{
p = x + x * x;
k = x * x + p;
return 0;
}
a) 30, 55
b) 55, 30
c) Compile time error
d) 0, 0
Answer :c
77. Keyword used to define call by reference parameter in C# .NET?
a) &
b) out
c) ref
d) &&
Answer :c
78. Select the correct match of parameter declaration:
static Void main(string[] args)
{
int a = 5;
int b = 6;
float c = 7.2f;
math (ref a, ref b, ref c);
Console.WriteLine(a + " " + b + " " + c);
}
9. static int math(/*add parameter decelaration */)
{
a += b;
b *= (int)c;
c += a * b;
return 0;
}
a) ref int a, int b, ref float c
b) ref int a, ref float c, ref int b
c) ref int a, ref int b, float c
d) ref int a, ref int b, ref float c
Answer :d
79. Which statement is/are correct?
a) An argument passed to a ref parameter need not to be initialized first
b) variables passed as out arguments need to be initialized prior to being passed
c) to use a ref parameter, only the calling method must explicitly use the ref keyword
d) None of the mentioned
Answer :d
80. The method in which large or variable number of arguments are handled is known as:
a) Value parameters
b) output parameters
c) parameter arrays
d) None of the mentioned
Answer :c
81. The modifiers used to define an array of parameters or list of arguments:
a) ref
b) out
c) param
d) var
Answer :c
82. What will be the output for the given set of code ?
static void Main(string[] args)
{
object[] a = {" 1 ", 4.0f, " harsh "};
fun(a);
Console.ReadLine();
}
static void fun(params object[] b)
{
for (int i = 0; i < b.Length - 1; i++)
Console.WriteLine(b[i] + " ");
}
a) 1 4.0 harsh
b) 1 4
c) 1 4 hars
d) 1 4 harsh
Answer :d
83. Which of the following statements are correct?
a) C SHARP allows a function to have arguments with default values
b) C SHARP allows a function to have variable number of arguments
c) Params is used to specify the syntax for a function with variable number of arguments
d) Omitting the return value type in method definition results into an exception
Answer :b, c
84. What will be the output of the 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 )
{
int[] k = { 3, 4, 7, 8,'\0' };
for (int i = 0; i < b.Length; i++)
{
b[i] = b[i] + k[i] ;
Console.WriteLine( b[i] + " ");
}
}
a) Compile time error
b) 3, 4, 7, 8, 5
c) 3, 4, 7, 8, 5, 1, 2, 3, 4, 5
d) 4, 6, 10, 12, 5
Answer :d
85. 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] + "");
}
}
a) 1, 2, 3, 4, 5
b) 5, 10, 15, 20, 25
c) 5, 25, 125, 625, 3125
d) 6, 12, 18, 24, 30
Answer :b
86. What will be the output of the given set of code?
static void Main(string[] args)
{
int[] a = { 2, 21, 34, 46, 85, 88, 90};
fun(a);
Console.WriteLine(a + " ");
Console.ReadLine();
}
static void fun(params int [] b )
{
int [] c = { 1, 2, 3, 4, 5, 6, 7};
int i ;
for (i = 0 ;i < b.Length ;i++)
if (b[i] % 2 == 0)
{
c[i] = b[i];
}
Console.WriteLine("even numbers are:");
for (i = 0 ;i <= b.Length ;i++)
{
Console.WriteLine(c[i]);
}
}
a) Compile time error
b) 2, 21, 34, 4, 6, 46, 88, 90
c) 2, 4, 34, 46, 6, 88, 90
d) 2, 34, 46, 88, 90
Answer :d
87. Select the correct declaration of the defining array of parameters:
a) void func(int[] x)
{
}
b) void func(int x)
{
}
c) void func(param int[])
{
}
d) void fun(param int[] x)
{
advertisements
}
Answer :d
88. What will be the output of the given set of code?
static void Main(string[] args)
{
int[] x = { 80, 82, 65, 72, 83, 67 };
fun(x);
Console.ReadLine();
}
static void fun(params int [] b )
{
int i;
for (i = 5; i >=0 ; i--)
{
Console.WriteLine(Convert.ToChar(b[i]));
}
}
a) 67 83 72 65 82 80
b) P R A H S C
c) C S H A R P
d) 80 82 65 72 83 67
Answer :c
89. What will be the output of the given set of code?
static void Main(string[] args)
{
int[] x = {65, 66, 67, 68, 69, 70};
fun(x);
Console.ReadLine();
}
static void fun(params int[] b )
{
int i;
for (i = 5; i > 0 ; i--)
{
b[i] = b[i] + 32;
Console.WriteLine(Convert.ToChar(b[i]));
}
}
a) A, B, C, D, E, F
b) F, E, D, C, B, A
c) f, e, d, c, b
d) b, c, d, e, f
Answer : c
Topic: 5
90. 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) None of the mentioned
Answer: a, b, c
91. Choose the keyword which declares the indexer?
a) base
b) this
c) super
d) extract
Answer: b
92. Choose the operator/operators which is/are used to access the [] operator in indexers?
a) get
b) set.t
c) access
d) All of the mentioned
Answer: a
93. 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
Answer: d
94. 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
Answer: b
95. 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) None of the mentioned
d) All of the mentioned
Answer: a, b
96. 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
Answer: d
97. 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)
b)
98.
c)
d)
group[3] = 34;
group g = new group();
g[3] = 34;
Console.WriteLine(group[3]);
group g = new group();
Console.WriteLine(g[3]);
Answer: b
99. 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
Answer: a, b
100.
Choose the output for the given set of code?
class list
{
ArrayList array = new ArrayList();
public object this[int index]
{
get
{
if (index < 0 || index >= array.Count)
{
return null;
}
else
{
return (array[index]);
}
}
set
{
array[index] = value;
}
}
public int Count
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
list list1 = new list();
list1[0] = "123";
list1[1] = " abc ";
list1[2] = "xyz";
for (int i = 0; i<=list1.Count; i++)
Console.WriteLine(list1[i]);
Console.ReadLine();
}
}
a) Compile time error
b) Run time error
c) 123, abc, xyz
d) 0
Answer: b
101.
Choose the correct statement about the properties used in C#.NET?
a) Each property consists of accessor as get and set
b) A property can 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
Answer: d
102.
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 above mentioned
Answer: d
103.
Where the properties can be declared?
a) Class
b) Struct
c) Interface
d) Namespace
Answer: a, b, c
104.
Select the modifiers which can be used with the properties?
a) Private
b) Public
c) Protected Internal
d) Protected
Answer: a, b, c, d
105.
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) None of the above mentioned
Answer: a, b, c
106.
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
Answer: c
107.
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
Answer: b
108.
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
Answer: a
109.
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) math m = new math();
m.add = m.add + 20;
Answer: b, d
110.
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;
Answer: c
111.
The correct way to implement a read only property add, in a math class is?
a)
class math
{
int ad;
public int add
{
get
{
return ad;
}
}
11.
}
b)
class math
{
public int add
{
get
{
return ad;
}
}
}
c)
class math
{
int ad;
public int add
{
get
{
return ad;
}
set
{
ad = value;
}
}
}
d) None of the mentioned
Answer: a
112.
The correct way to implement a write only property add in a math class?
a)
class math
{
public int add
{
set
{
add = value;
}
}
}
b)
class math
{
int ad;
public int add
{
set
{
ad = value;
}
}
}
c)
class math
{
int ad;
public int add
{
get
{
return ad;
}
set
{
ad = value;
}
}
}
d) None of the mentioned
Answer: b
113.
Select the correct statement about properties of read and write in C#.NET?
a) A property can simultaneously be read or write only
b) A property can be either read only or write only
c) A write only property will only have get accessor
d) A read only property will only have get accessor
Answer: b, d
114.
What will be the output of following snippet of code?
class number
{
private int num1;
private int num2;
public int anumber
{
get
{
return num1;
}
set
{
num1 = value;
}
}
public int anumber1
{
get
{
return num2;
}
set
{
num2 = value;
}
}
}
class Program
{
public static void Main(string[] args)
{
number p = new number();
p.anumber = 20;
number k = new number();
k.anumber1 = 40;
int m = p.anumber;
int t = k.anumber1;
int r = p.anumber + k.anumber1;
Console.WriteLine("number = " +m);
Console.WriteLine("number = " +t);
Console.WriteLine("sum = " +r);
Console.ReadLine();
}
}
a) 0
b) Compile time error
c) 60
d) None of the above mentioned
Answer: c
115.
What will be the output of the following snippet of code?
class number
{
private int num1 = 60;
private int num2 = 20;
public int anumber
{
get
{
return num1;
}
set
{
num1 = value;
}
}
public int anumber1
{
get
{
return num2;
}
set
{
num2 = value;
}
}
}
class Program
{
public static void Main(string[] args)
{
number p = new number();
number k = new number();
int m = p.anumber;
int t = k.anumber1;
int r = p.anumber * k.anumber1;
Console.WriteLine("sum = " + r);
Console.ReadLine();
}
}
a) 0
b) 120
c) 1200
d) Compile time error
Answer: c
116.
What will be the output of the following snippet of code?
class number
{
int length = 50;
public int number1
{
get
{
return length;
}
set
{
length = value;
}
}
}
class Program
{
public static void Main(string[] args)
{
number p = new number();
p.number1 = p.number1 + 40;
int k = p.number1 * 3 / 9;
Console.WriteLine(k);
Console.ReadLine();
}
}
a) 0
b) 180
c) 30
d) Compile time error
Answer: c
117.
What will be the output of the following snippet of code?
class number
{
int length = 60;
public int number1
{
get
{
return length;
}
}
}
class Program
{
public static void Main(string[] args)
{
number p = new number();
int l;
l = p.number1 + 40;
int k = l * 3 / 4;
Console.WriteLine(k);
Console.ReadLine();
}
}
a) 30
b) 75
c) 80
d) 0
Answer: b
118.
What will be the output of the following snippet of code?
655060566571343ea396b1_000010
a) 73
b) 37
c) 0
d) Run time error
Answer: a
119.
The correct way to implement the property for which property reports the error
“invalid index” if user attempts to cross bounds of the array for a student class with 5 intger
arrays.
a) class student
{
int []scores = new int[5] {23, 42, 54, 11, 65};
public int this[int index]
{
get
{
if (index < 5)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
set
{
if (index < 5)
scores[index] = value;
else
Console.WriteLine("invalid index");
}
}
}
b)
class student
{
int []scores = new int[5] {23, 42, 54, 11, 65};
public int this[int index]
{
get
{
if (index < 5)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
}
}
c)
class student
{
int []scores = new int[5]{23, 42, 54, 11, 65};
public int this[int index]
{
set
{
if (index < 5)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
}
}
d) None of the above mentioned
Answer: b
120.
What will be the output of the following snippet of code?
class student
{
int []scores = new int[3] {13, 32, 24};
public int this[int index]
{
get
{
if (index < 3)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
private set
{
if (index < 3)
scores[index] = value;
else
Console.WriteLine("invalid index");
}
}
}
class Program
{
public static void Main(string[] args)
{
student s = new student();
int[] scores1 = new int[3] {8, 19, 40};
for (int i = 0; i < 3; i++)
{
if (scores1[i] > s[i])
{
Console.WriteLine(" scores1 had greater value :" + scores1[i]);
}
else
{
Console.WriteLine("scores had greater value :" + s[i]);
}
}
Console.ReadLine();
}
}
a) 0
b) Compile time error
c) Run time error
d) scores had greater value : 13
scores had greater value : 32
scores1 had greater value : 40
Answer: d
121.
Which among the following is NOT an exception?
a) Stack Overflow
b) Arithmetic Overflow or underflow
c) Incorrect Arithmetic Expression
d) All of the above mentioned
Answer :c
122.
Which among the following is NOT considered as .NET Exception class?
a) Exception
b) StackUnderflow Exception
c) File Found Exception
d) Divide By zero Exception
Answer :b, c
123.
Which of the following is the object oriented way to handle run time errors?
a) Error codes
b) HERRESULT
c) OnError
d) Exceptions
Answer :d
124.
Select the statements which describe the correct usage of exception handling over
conventional error handling approaches?
a) As errors can be ignored but exceptions cannot be ignored
b) Exception handling allows separation of program’s logic from error handling logic making
software more reliable and maintainable
c) try – catch – finally structure allows guaranteed cleanup in event of errors under all
circumstances
d) All of the above mentioned
Answer :d
125.
Select the correct statement about an Exception?
a) It occurs during loading of program
b) It occurs during Just-In-Time compilation
c) It occurs at run time
d) All of the above mentioned
Answer :c
126.
Which of these keywords is not a part of exception handling?
a) try
b) finally
c) thrown
d) catch
Answer :c
127.
Which of these keywords must be used to monitor exceptions?
a) try
b) finally
c) throw
d) catch
Answer :a
128.
Which of these keywords is used to manually throw an exception?
a) try
b) finally
c) throw
d) catch
Answer :c
129.
Choose the correct output for the given set of code:
class program
{
static void main(string[] args)
{
int i = 5;
int v = 40;
int[] p = new int[4];
try
{
p[i] = v;
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("Index out of bounds");
}
Console.WriteLine("Remaining program");
}
}
a) value 40 will be assigned to a[5];
The output will be :
b) Index out of bounds
Remaining program
c) The output will be :
Remaining program
d) None of the above mentioned
Answer :b
130.
Choose the correct output for the given set of code:
static void Main(string[] args)
{
try
{
Console.WriteLine("csharp" + " " + 1/Convert.ToInt32(0));
}
catch(ArithmeticException e)
{
Console.WriteLine("Java");
}
Console.ReadLine();
}
a) csharp
b) java
c) Run time error
d) csharp 0
Answer :b
131.
Which of the following is the correct statement about exception handling in C#.NET?
a) finally clause is used to perform cleanup operations of closing network and database
connections
b) a program can contain multiple finally clauses
c) The statement in final clause will get executed no matter whether an exception occurs or
not
d) All of the above mentioned
Answer : c
132.
Choose the correct output for given set of code:
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("csharp" + " " + 1/0);
}
finally
{
Console.WriteLine("Java");
}
Console.ReadLine();
}
}
a) csharp 0
b) Run time Exception generation
c) Compile time error
d) Java
Answer : b
133.
What will be the output of the following set of code?
{
int sum = 10;
try
{
int i;
for (i = -1; i < 3; ++i)
sum = (sum / i);
}
catch (ArithmeticException e)
{
Console.WriteLine("0");
}
Console.WriteLine(sum);
Console.ReadLine();
}
a) 0
b) 0 5
c) 0 -10
d) Compile time error
Answer :c
134.
What will be the output of the following set of code?
{
try
{
int []a = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; ++i)
Console.WriteLine(a[i]);
int x = (1 / Convert.ToInt32(0));
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("A");
}
catch(ArithmeticException e)
{
Console.WriteLine("B");
}
Console.ReadLine();
}
a) 1234
b) 12345
c) Run time error
d) 12345B
Answer : a
135.
3. What will be the output of given code snippet?
{
try
{
int []a = {1, 2, 3, 4, 5};
for (int i = 0; i < 7; ++i)
Console.WriteLine(a[i]);
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("0");
}
Console.ReadLine();
}
a) 12345
b) 123450
c) 1234500
d) Compile time error
Answer :b
136.
What would be the output of following code snippet?
{
try
{
int a, b;
b = 0;
a = 10 / b;
Console.WriteLine("A");
}
catch(ArithmeticException e)
{
Console.WriteLine("B");
}
Console.ReadLine();
}
a) A
b) B
c) Compile time error
d) Run time error
Answer :b
137.
What would be the output of following code snippet?
{
try
{
int i, sum;
sum = 10;
for (i = -1 ;i < 3 ;++i)
{
sum = (sum / i);
Console.WriteLine(i);
}
}
catch(ArithmeticException e)
{
Console.WriteLine("0");
}
Console.ReadLine();
}
a) -1
b) 0
c) -1 0
d) -1 0 -1
Answer: c
138.
What would be the output of following code snippet?
{
try
{
int a, b;
b = 0;
a = 5 / b;
Console.WriteLine("A");
}
catch(ArithmeticException e)
{
Console.WriteLine("B");
}
finally
{
Console.WriteLine("C");
}
Console.ReadLine();
}
a) A
b) B
c) B C
d) Run time error
Answer: c
139.
What would be the output of given code snippet?
class Program
{
static void Main(string[] args)
{
int i;
int v = 40;
int[] x = new int[5];
try
{
Console.WriteLine(" Enter the number: ");
index = Convert.ToInt32(Console.ReadLine());
x[index] = v;
}
catch(Exception e)
{
Console.WriteLine("Exception occured");
}
Console.WriteLine("Program executed");
}
}
a) Exception occured
b) Program executed
c) Exception occured
Program executed
d) Program executed
Exception occured
Answer :c
140.
When no exception is thrown at runtime then who will catch it?
a) CLR
b) Operating System
c) Loader
d) Compiler
Answer :a
141.
What would be the output of given code snippet?
public static void Main(string[] args)
{
try
{
int a, b, c = 5;
b = 0;
a = c / b;
Console.WriteLine("A");
}
catch (ArithmeticException e)
{
int c = 5;
int i = 10;
int z = 2 * c - i;
Console.WriteLine("B");
Console.WriteLine(z);
}
Console.ReadLine();
}
a) Compile time error
b) Run time error
c) B 0
d) B
Answer :c
142.
Choose the correct statement which makes exception handling work in C#.NET?
a) .Net runtime makes search for the exception handler where exception occurs
b) If no exception is matched, exception handler goes up the stack and hence finds the match
there
c) If no match is found at the highest level of stack call, then unhandledException is generated
and hence termination of program occurs
d) None of the mentioned
Answer : a, b, c
143.
Which of these clauses will be executed even if no exceptions are found?
a) throws
b) finally
c) throw
d) catch
Answer: b
144.
A single try block must be followed by which of these?
a) finally
b) catch
c) Both a & b
d) None of the mentioned
Answer: c
145.
Which of these exceptions handles the divide by zero error?
a) ArithmeticException
b) MathException
c) IllegalAccessException
d) IllegarException
Answer: a
146.
Which of these exceptions will occur if we try to access the index of an array beyond
its length?
a) ArithmeticException
b) ArrayException
c) ArrayArguementException
d) IndexOutOfRangeException
Answer: d
147.
What will be the output of the given code snippet?
class program
{
public static void Main(string[] args)
{
try
{
int a = args.Length;
int b = 1 / a;
Console.WriteLine(a);
}
catch (ArithmeticException e)
{
Console.WriteLine("1");
}
Console.ReadLine();
}
}
a) 0
b) 1
c) Compile time error
d) Runtime error
Answer: b
148.
What will be the output of given code snippet?
class program
{
public static void Main(string[] args)
{
try
{
throw new NullReferenceException("C");
Console.WriteLine("A");
}
catch (ArithmeticException e)
{
Console.WriteLine("B");
}
Console.ReadLine();
}
}
a) A
b) B
c) Compile time error
d) Runtime error
Answer: d
149.
What will be the output of the given code snippet?
class Program
{
public static void Main(string[] args)
{
try
{
int a = 1;
int b = 10 / a;
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int[] c = { 1 };
c[8] = 9;
}
}
finally
{
Console.WriteLine("A");
}
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("B");
}
Console.ReadLine();
}
}
a) A
b) B
c) AB
d) BA
Answer: a
150.
What will be the output of the given code snippet?
class Program
{
public static void Main(string[] args)
{
try
{
int a = args.Length;
int b = 10 / a;
Console.WriteLine(a);
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int[] c = { 1 };
c[8] = 9;
}
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("TypeA");
}
}
catch (ArithmeticException e)
{
Console.WriteLine("TypeB");
}
Console.ReadLine();
}
}
a) TypeA
b) TypeB
c) 0TypeA
d) Compile time error
Answer :b
151.
Which of the following keywords is used by the calling function to guard against the
exception that is thrown by called function?
a) try
b) throw
c) throws
d) catch
Answer :c
152.
Which of these classes is related to all the exceptions that are explicitly thrown?
a) Error
b) Exception
c) Throwable
d) Throw
Answer :c
153.
What is the use of try & catch?
a) It is used to manually handle the exception
b) It helps to fix the errors
c) It prevents automatic terminating of the program in cases when an exception occurs
d) All of the mentioned
Answer: d
154.
What is the output of this program?
a. class Output
b. {
c. public static void main(String args[])
d. {
b) 5.
a. try
b. {
c. int a = 9;
d. int b = 5;
e. int c = a / b - 5;
f. Console.WriteLine("Hello");
g. }
h. catch(Exception e)
i. {
j. Console.WriteLine("C");
k. }
l. finally
m. {
n. Console.WriteLine("sharp");
o. }
p. }
q. }
a) Hello
b) C
c) Hellosharp
d) Csharp
Answer: d
155.
Choose the statement which is incorrect?
a) try block does not need to be followed by catch block
b) try block can be followed by finally block instead of catch block
c) try can be followed by both catch and finally block
d) try need not to be followed by anything
Answer: d
156.
What will be the output of the program?
class Output
{
public static void main(String args[])
{
try
{
int a = 10;
int b = 5;
int c = a / b - 5;
Console.WriteLine("Hi");
}
catch(Exception e)
{
Console.WriteLine("hello");
}
}
}
a) Hi
b) hello
c) Hihello
d) Compile time error
Answer: b
157.
Which of the keywords are used for the block to be examined for exceptions?
a) try
b) catch
c) throw
d) check
Answer: a
158.
Which of these keywords are used for the block to handle the exceptions generated
by try block?
a) try
b) catch
c) throw
d) check
Answer :b
159.
What is the output of this program?
class Output
{
public static void main(String args[])
{
try
{
int a = 5;
int b = 10;
int c = b / a - 5;
Console.WriteLine("Csharp");
}
}
}
a) Csharp
b) sharp
c) C
d) Compile time error
Answer: d
160.
What is the output of the given code snippet?
class Output
{
public static void main(String args[])
{
try
{
int a = 0;
int b = 5;
int c = a / b - 5;
Console.WriteLine("C");
}
finally
{
Console.WriteLine("sharp");
}
}
}
a) C
b) sharp
c) Csharp
d) None of the mentioned
Answer: c
161.
What will be the output of the code snippet?
class Output
{
public static void main(String args[])
{
try
{
int a = 10;
int b = 5;
int c = b - 5 / 5;
Console.WriteLine("Hi");
}
catch(Exception e)
{
Console.WriteLine("hello");
}
}
}
a) Hi
b) hello
c) Hihello
d) Compile time error
Answer: a
162.
Which of these keywords are used for generating an exception manually?
a) try
b) catch
c) throw
d) check
Answer: c
163.
The ‘ref’ keyword can be used with which among the following?
a) static function/subroutine
b) static data
c) Instance function/subroutine
d) instance data
Answer: c
164.
To implement delegates, the necessary condition is?
a) class declaration
b) inheritance
c) run time polymorphism
d) exceptions
Answer: a
165.
Suppose a Generic class called as SortObjects is to be made capable of sorting
objects of any type(integer, single, byte etc).Then, which of the following programming
constructs is able to implement the comparison function?
a) interface
b) encapsulation
c) delegate
d) attribute
Answer: c
Explanation: None.
166.
To generate a simple notification for an object in runtime, the programming
construct to be used for implementing this idea?
a) namespace
b) interface
c) delegate
d) attribute
Answer: c
167.
Choose the incorrect statement among the following about the delegate?
a) delegates are of reference types
b) delegates are object oriented
c) delegates are type safe
d) none of the mentioned
Answer: d
168.
Which among the following is the correct statement about delegate declaration ?
delegate void del(int i);
a) On declaring the delegate, a class called del is created
b) the del class is derived from the MulticastDelegate class
c) the del class will contain a one argument constructor and an invoke() method
d) none of the mentioned
Answer: b,
169.
Which of the following is an incorrect statement about delegate?
a) A single delegate can invoke more than one method
b) delegates could be shared
c) delegates are type safe wrappers for function pointers
d) delegate is a value type
Answer: c
170.
Which among the following differentiates a delegate in C#.NET from a conventional
function pointer in other languages?
a) delegates in C#.NET represent a new type in the Common Type System
b) delegates allows static as well as instance methods to be invoked
c) delegates are type safe and secure
d) none of the mentioned
Answer: d
171.
Choose the incorrect statement about delegates?
a) delegates are not type safe
b) delegates cannot be used to implement callback notification
c) delegate is a user defined type
d) delegates permits execution of a method in an asynchronous manner
Answer: a, b
172.
Which of the following statements is correct about a delegate?
a) inheritance is a prerequisite for using delegates
b) delegates are data types
c) delegates provides wrappers for function pointers
d) none of the mentioned
Answer: b
173.
Choose the correct way to call subroutine fun() of the sample class?
class a
{
public void x(int p, double k)
{
Console.WriteLine("k : csharp!");
}
}
a) delegate void del(int i);
x s = new x();
del d = new del(ref s.x);
d(8, 2.2f);
b) delegate void del(int p, double k);
del d;
x s = new x();
d = new del(ref s.x);
d(8, 2.2f);
c) x s = new x();
delegate void d = new del(ref x);
d(8, 2.2f);
d) all of the mentioned
Answer: b
174.
2. Which of the following is the correct way to call the function abc() of the given
class csharp given below?
class csharp
{
public int abc(int a)
{
Console.WriteLine("A:Just do it!");
return 0;
}
}
a) delegate void del(int a);
csharp s = new csharp();
del d = new del(ref s.abc);
d(10);
b) csharp s = new csharp();
delegate void d = new del(ref abc);
d(10);
c) delegate int del(int a);
del d;
csharp s = new csharp();
d = new del(ref s.fun);
d(10);
d) none of the mentioned
Answer: c
175.
3. Which of the following is the correct way to call the subroutine function abc() of
the given class csharp given below?
class csharp
{
void abc()
{
console.writeline("A:Just do it!");
}
}
a) csharp c = new csharp();
delegate void d = new del(ref abc);
d();
b) delegate void del();
del d;
csharp s = new csharp();
d = new del(ref s.abc);
d();
c) delegate void del();
abc s = new abc();
del d = new del(ref s.abc);
d();
d) csharp s = new csharp();
delegate void del = new delegate(ref abc);
del();
Answer: b, c
176.
4. What will be the output of the given code snippet below?
{
delegate void A(ref string str);
class sample
{
public static void fun( ref string a)
{
a = a.Substring( 7, a.Length - 7);
}
}
class Program
{
static void Main(string[] args)
{
A str1;
string str = "Test Your C#.net skills";
str1 = sample.fun;
str1(ref str);
Console.WriteLine(str);
}
}
}
a) Test Your
b) ur C#.NET
c) ur C#.NET Skills
d) None of the mentioned
Answer: c
177.
5. What will be the output of the given code snippet below?
{
delegate string F(string str);
class sample
{
public static string fun(string a)
{
return a.Replace(',''-');
}
}
class Program
{
static void Main(string[] args)
{
F str1 = new F(sample.fun);
string str = str1("Test Your c#.NET skills");
Console.WriteLine(str);
}
}
}
a) Test Your
b) Test-Your-C#.NET-Skills
c) ur C#.NET Skills
d) None of the mentioned
Answer: b
178.
Choose the statements which makes delegate in C#.NET different from a normal
class?
a) Delegates in C#.NET is a base class for all delegates type
b) Delegates created in C#.NET are further not allowed to derive from the delegate types that
are created
c) Only system and compilers can derive explicitly from the Delegate or MulticasteDelegate
class
d) All of the mentioned
Answer: d
179.
Which of the following are the correct statements about delegates?
a) Delegates can be used to implement callback notification
b) Delegates permit execution of a method on a secondary thread in an asynchronous manner
d) Delegate is a user defined type
e) None of the mentioned
Answer: a
180.
8. What will be the output of given set of code?
{
delegate string f(string str);
class sample
{
public static string fun(string a)
{
return a.Replace('k', 'o');
}
}
class Program
{
static void Main(string[] args)
{
f str1 = new f(sample.fun);
string str = str1("Test Ykur C#.NET Skills");
Console.WriteLine(str);
Console.ReadLine();
}
}
}
a) Test Ykur C#.NET Skills
b) Test Ykour C#.NET Skills
c) Test Your C#.NET Skills
d) Test ur C#.NET Skills
Answer: c
181.
Incorrect statements about delegates are?
a) Delegates are reference types
b) Delegates are object oriented
c) Delegates are type safe
d) Only one method can be called using a delegate
Answer: d
182.
Select the modifiers which control the accessibility of the delegate:
a) new
b) protected
c) public
d) internal
Answer: a, b, c, d
183.
. What is meant by the term generics?
a) parameterized types
b) class
c) structure
d) interface
Answer: a
184.
Are generics in C# are same as the generics in java and templates in C++?
a) Yes
b) No
c) May be
d) None of the mentioned
Answer: b
185.
Choose the advantages of using generics?
a) Generics facilitate type safety
b) Generics facilitate improved performance and reduced code
c) Generics promote the usage of parameterized types
d) All of the mentioned
Answer: d
186.
What does the following code block defines?
class Gen<T> {
T ob;
}
a) Generics class declaration
b) Decleration of variable
c) a simple class declaration
d) All of the mentioned
Answer: b
187.
What does the following code set defines?
public Gen(T o) {
ob = o;
}
a) Generics class decleration
b) Declaration of variable
c) Generic constructor declaration
d) All of the mentioned
Answer: c
188.
Select the type argument of an open constructed type?
a) Gen
b) Gen
c) Gen<>
d) None of the mentioned
Answer: c
189.
Which among the given classes is present in System.Collection.Generic.namespace?
a) Stack
b) Tree
c) Sorted Array
d) All of the mentioned
Answer: a
190.
8. Which of these is a correct way of defining generic method?
a) name(T1, T2, …, Tn) { /* … */ }
b) public name { /* … */ }
c) class name[T1, T2, …, Tn] { /* … */ }
d) name{T1, T2, …, Tn} { /* … */ }
Answer: b
191.
Which of these type parameters is used for generic methods to return and accept
any type of object?
a) K
b) N
c) T
d) V
Answer: c
192.
10. Choose the correct way to call subroutine fun() of the sample class?
class a
{
public void x(int p, double k)
{
Console.WriteLine("k : csharp!");
}
}
a) delegate void del(int i);
x s = new x();
del d = new del(ref s.x);
d(8, 2.2f);
b) delegate void del(int p, double k);
del d;
x s = new x();
d = new del(ref s.x);
d(8, 2.2f);
c) x s = new x();
delegate void d = new del(ref x);
d(8, 2.2f);
d) all of the mentioned
Answer: b
193.
11. What will be the output of the given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<string> g = new Generic<string>();
g.push(40);
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
a) 0
b) Runtime Error
c) 40
d) Compile time Error
Answer: c
194.
What will be the output of the given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<int> g = new Generic<int>();
g.push("Csharp");
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
a) Compile time error
b) Csharp
c) 0
d) Run time error
Answer: b
195.
For the code set given below,which of the following statements are perfectly valid?
public class MyContainer<T> where T: class, IComparable
{
/* insert code here */
}
a) Class MyConatiner requires that its type argument must implement Icomparable interface
b) There are multiple constraints on type argument to MyConatiner class
c) Compiler will report an error
d) None of the mentioned
Answer: b
196.
For the code given below which statements are perfectly valid?
public class Csharp
{
public void subject<S>(S arg)
{
Console.WriteLine(arg);
}
}
class Program
{
static Void Main(string[] args)
{
Csharp c = new Csharp();
c.subject("hi");
c.subject(20);
}
}
a) Run time exception error
b) Compile time error
c) Code runs successfully and prints required output
d) None of the mentioned
Answer: c
197.
Which of given statements are valid about generics in .NET Framework?
a) generics are useful in collection classes in .NET framework
b) generics delegates are not allowed in C#.NET
c) generics is a language feature
d) All of the mentioned
Answer: c, a
198.
Which statement is valid for the given snippet of code:
public class Generic<T>
{
public T Field;
}
class Program
{
static void Main(string[] args)
{
Generic<String> g = new Generic<String>();
g.Field = "Hi";
Console.WriteLine(g.Field);
}
}
a) Compile time error
b) Generic being a keyword cannot be used as a class name
c) run time error
d) Code runs successfully
Answer: d
199.
Choose the output for given set of code:
public class Generic<T>
{
public T Field;
}
class Program
{
static void Main(string[] args)
{
Generic<int> g2 = new Generic<int>();
Generic<int> g3 = new Generic<int>();
g2.Field = 8;
g3.Field = 4;
if (g2.Field % g3.Field == 0)
{
Console.WriteLine("A");
}
else
Console.WriteLine("Prints nothing:");
Console.ReadLine();
}
}
a) Compile time error
b) A
c) run time error
d) Code runs successfully but prints nothing
Answer: b
200.
Which of the following is a valid statement about generic procedures in C#.NET are?
a) All procedures in a Generic class are generic
b) Generic procedures should take at least one type parameter
c) Only those procedures labeled as Generic are Generic
d) None of the mentioned
Answer: b
201.
For the code set given below,which of the following statements are perfectly valid?
public class MyContainer<T> where T: IComparable
{
/* insert code here */
}
a) Class MyConatiner requires that its type arguement must implement Icomparable interface
b) There are multiple constraints on type arguement to MyContainer class
c) Type arguement of class MyContainer should be Icomparable
d) None of the mentioned
Answer: a
202.
Choose the statements which are valid for given code snippet:
public class Generic<T>
{
public T Field;
public void testSub()
{
T i = Field + 1;
}
}
class Program
{
static void Main(string[] args)
{
Generic<int>g = new Generic<int>();
g.testSub();
}
}
a) code runs successfully but prints nothing
b) code runs successfully and prints 1
c) Program will give run time error
d) Compile time error
Answer: d
203.
Which among the given classes represents System.Collections.Generic namespace?
a) SortedDictionary
b) Sorted Array
c) Stack
d) Tree
Answer: c
204.
10. What will be the output of given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<int> g = new Generic<int>();
g.push("Csharp");
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
a) Compile time error
b) Csharp
c) 0
d) Run time error
Answer: b
205.
What will be the output of the given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<string> g = new Generic<string>();
g.push(30);
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
a) 0
b) 30
c) Runtime Error
d) Compile time Error
Answer: b
206.
What will be the output of the given code snippet?
public class Generic<T>
{
Stack<T> stk = new Stack<T>();
public void push(T obj)
{
stk.Push(obj);
}
public T pop()
{
T obj = stk.Pop();
return obj;
}
}
class Program
{
static void Main(string[] args)
{
Generic<string> g = new Generic<string>();
g.push("C++");
Console.WriteLine(g.pop() + " ");
Generic<int> g1 = new Generic<int>();
g1.push(20);
Console.WriteLine(g1.pop());
Console.ReadLine();
}
}
a) C++
b) 20
c) C++
20
d) 0
Answer: c
207.
Assume 2 columns named as Product and Category how can be both sorted out
based on first by category and then by product name?
a) var sortedProds = _db.Products.Orderby(c => c.Category)
b) var sortedProds = _db.Products.Orderby(c => c.Category) + ThenBy(n => n.Name)
c) var sortedProds = _db.Products.Orderby(c => c.Category) . ThenBy(n => n.Name)
d) All of the mentioned
Answer: c
208.
Choose the correct statements about the LINQ?
a) The main concept behind the linq is query
b) linq makes use of foreach loop to execute the query
c) It is not required that linq should make use of IEnumerable interface
d) None of the mentioned
Answer: a, b
209.
Choose the namespace in which the interface IEnumerable is declared?
a) System.Collections
b) System.Collections.Generic
c) Both a & b
d) None of the mentioned
Answer: b
210.
Can we use linq to query against a DataTable?
a) Yes
b) No
c) Either a or b
d) None of the mentioned
Answer: b
211.
What will be the output of given code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5};
var posNums = from n in nums
where n >= 0
select n;
foreach (int i in posNums)
Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) 0, 1, -2, -4, 5
b) 1, 3, 0, 5
c) 1, 3, 5
d) Run time error
Answer: b
212.
Select the namespace which should be included while making use of LINQ
operations:
a) System.Text
b) System.Collections.Generic
c) System.Linq
d) None of the mentioned
Answer: c
213.
Select the output for the given code snippet:
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n % 2 ==0
select n;
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) code run successfully prints nothing
b) run time error
c) code run successfully and executes output
d) compile time error
Answer: c
214.
Select the output for given code snippet:
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n > -5 && n < 6
orderby n descending
select n;
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) Prints nothing code runs successfully
b) Run time error
c) Arranged in descending order code runs successfully
d) Compile time error
Answer: c
215.
Select the output for given code snippet:
class Program
{
static void Main(string[] args)
{
int[] nums = { 16, 9, 25};
var posNums = from n in nums
where n > 0
select Math.Sqrt(n);
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) code runs successfully prints nothing
b) code runs successfully prints required output
c) Run time error
d) Compile time error
Answer: b
216.
Select the output for given code snippet:
class Program
{
static void Main(string[] args)
{
int[] nums = {1};
var posNums = from n in nums
wheres n > 0
select Math.Max(78, 9);
Console.Write("The largest values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) code runs successfully prints nothing
b) Run time error
c) code runs successfully prints required output
d) Compile time error
Answer: c
217.
What will be the output of the given code snippet?
class Program
{
static void Main(string[] args)
{
string[] strs = {"alpha", "beta", "gamma"};
var chrs = from str in strs
let chrArray = str.ToCharArray()
from ch in chrArray
orderby ch
select ch;
Console.WriteLine("The individual characters in sorted order:");
foreach (char c in chrs)
Console.Write(c + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) a a l h a b g m m a p e t a
b) a a a a a b e g h l m m p t
c) a g h l m m p t a a a a b e
d) Run time error
Answer: b
218.
What will be the output of the given code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = nums.Where(n => n > 0).Select(r => r*2).OrderByDescending(r=>r);
Console.Write("The positive values in nums: ");
foreach(int i in posNums)
Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) code run successfully prints nothing
b) run time error
c) code run successfully prints multiple of 2
d) compile time error
Answer: c
219.
What will be the output of the given code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = {3, 1, 2, 5, 4};
var ltAvg = from n in nums
let x = nums.Average()
where n < x
select n;
Console.WriteLine("The average is " + nums.Average());
Console.ReadLine();
}
}
a) Run time error
b) 3
c) 5
d) Compile time error
Answer: b
220.
What will be the output of the given code snippet?
class Program
{
static void Main(string[] args)
{
Expression<Func<int, int, bool>>
IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false;
Func<int, int, bool> IsFactor = IsFactorExp.Compile();
if (IsFactor(10, 5))
Console.WriteLine("5 is a factor of 10.");
if (!IsFactor(343, 7))
Console.WriteLine("7 is not a factor of 10.");
Console.ReadLine();
}
}
a) Compile time error
b) Run time error
c) 5 is a factor of 10
7 is not a factor of 10
d) 5 is a factor of 10
Answer: d
221.
Choose the namespace in which Expression trees are encapsulated:
a) System.Linq
b) System.Linq.Expressions
c) System.Text
d) System.Collections.Generic
Answer: b
222.
For the given set of codes, which query will work according to the set of code?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
int len = /*_________________ */
Console.WriteLine("The number of positive values in nums: " + len);
Console.ReadLine();
}
}
a) from n in nums where n > 0
select n
b) from n in nums where n > 0
select n.Count()
c) (from n in nums where n > 0
select n).Count();
d) Both b & c
Answer: c
223.
For the given set of code, what does the output represent?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n > 0
select n;
int len = posNums.Count();
Console.WriteLine(len);
Console.ReadLine();
}
}
a) Execution of code with nothing being printed
b) Execution of code with printing all numbers
c) Execution of code with counting total numbers greater than zero
d) Run time error
Answer: c
224.
8. For the given set of codes, what is the output?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = nums.Where(n => n < 10).Select(r => r%3);
Console.Write("The values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) Compile time error
b) Run time error
c) 1 -2 0 0 -1 2
d) 2 -1 0 0 -2 1
Answer: c
225.
For the given set of codes, what is the output?
class Program
{
static void Main(string[] args)
{
string[] strs = { ".com", ".net", "facebook.com", "google.net", "test", "netflix.net",
"hsNameD.com" };
var netAddrs = from addr in strs
where addr.Length > 4 && addr.EndsWith(".net",
StringComparison.Ordinal)
select addr;
foreach (var str in netAddrs) Console.WriteLine(str);
Console.ReadLine();
}
}
a) Compile time error
b) Run time error
c) facebook.com
netflix.net
google.net
d) google.net
netflix.net
Answer: d
226.
For the given set of codes, what is the output?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, -3, 5 };
var posNums = from n in nums
orderby n descending
select n*4 / 2;
Console.Write("The values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) 10 2 -4 -6
b) 5 1 -2 -3
c) 1 5 -2 -3
d) Run time error
Answer: a
Download