Answer: Option C
6. |
Which of the following statements is correct about the C#.NET code snippet given below?
int d;
d = Convert.ToInt32( !(30 < 20) );
|
A. |
A value 0 will be assigned to d. |
B. |
A value 1 will be assigned to d. |
C. |
A value -1 will be assigned to d. |
D. |
The code reports an error. |
E. |
The code snippet will work correctly if ! is replaced by Not. |
Answer: Option B
Explanation:
Sample Program:
bool falseFlag = false;
bool trueFlag = true;
Console.WriteLine("{0} converts to {1}.", falseFlag,
Convert.ToInt32(falseFlag));
Console.WriteLine("{0} converts to {1}.", trueFlag,
Convert.ToInt32(trueFlag));
The example displays the following output:
False converts to 0.
True converts to 1.
Solved MCQs From: http://cs-mcqs.blogspot.com
|
7. |
Which of the following is the correct output for the C#.NET code snippet given below?
Console.WriteLine(13 / 2 + " " + 13 % 2);
|
|
8. |
Which of the following statements are correct about the Bitwise & operator used in C#.NET?
- The & operator can be used to Invert a bit.
- The & operator can be used to put ON a bit.
- The & operator can be used to put OFF a bit.
- The & operator can be used to check whether a bit is ON.
- The & operator can be used to check whether a bit is OFF.
|
A. |
1, 2, 4 |
B. |
2, 3, 5 |
C. |
3, 4 |
D. |
3, 4, 5 |
E. |
None of these |
|
Solved MCQs From: http://cs-mcqs.blogspot.com
9. |
Which of the following are Logical operators in C#.NET?
- &&
- ||
- !
- Xor
- %
|
A. |
1, 2, 3 |
B. |
1, 3, 4 |
C. |
2, 4, 5 |
D. |
3, 4, 5 |
E. |
None of these |
|
10. |
Suppose n
is a variable of the type Byte and we wish, to check whether its fourth
bit (from right) is ON or OFF. Which of the following statements will
do this correctly? |
A. |
if ((n&16) == 16)
Console.WriteLine("Third bit is ON");
|
B. |
if ((n&8) == 8)
Console.WriteLine("Third bit is ON");
|
C. |
if ((n ! 8) == 8)
Console.WriteLine("Third bit is ON");
|
D. |
if ((n ^ 8) == 8)
Console.WriteLine("Third bit is ON");
|
E. |
if ((n ~ 8) == 8)
Console. WriteLine("Third bit is ON");
|
Answer: Option B
Explanation:
byte myByte = 153; // In Binary = 10011001
byte n = 8; // In Binary = 00001000
(Here 1 is the 4th bit from right)
Now perform logical AND operation (n & myByte)
10011001
00001000
---------
00001000 Here result is other than 0, so evaluated to True.
---------
If the result is true, then we can understand that 4th bit is ON of the given data myByte.
Solved MCQs From: http://cs-mcqs.blogspot.com
CONSTRUCTORS
1. |
Which of the following statements is correct? |
A. |
A constructor can be used to set default values and limit instantiation. |
B. |
C# provides a copy constructor. |
C. |
Destructors are used with classes as well as structures. |
D. |
A class can have more than one destructor. |
|
2. |
Which of the following statements is correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class Sample
{
public int func()
{
return 1;
}
public Single func()
{
return 2.4f ;
}
}
class Program
{
static void Main(string[ ] args)
{
Sample s1 = new Sample();
int i;
i = s1.func();
Single j;
j = s1.func();
}
}
}
|
A. |
func() is a valid overloaded function. |
B. |
Overloading works only in case of subroutines and not in case of functions. |
C. |
func() cannot be considered overloaded because: return value cannot be used to distinguish between two overloaded functions. |
D. |
The call to i = s1.func() will assign 1 to i. |
E. |
The call j = s1.func() will assign 2.4 to j. |
|
3. |
Which of the following ways to create an object of the Sample class given below will work correctly?
class Sample
{
int i;
Single j;
double k;
public Sample (int ii, Single jj, double kk)
{
i = ii;
j = jj;
k = kk;
}
}
|
A. |
Sample s1 = new Sample(); |
B. |
Sample s1 = new Sample(10); |
C. |
Sample s2 = new Sample(10, 1.2f); |
D. |
Sample s3 = new Sample(10, 1.2f, 2.4); |
E. |
Sample s1 = new Sample(, , 2.5); |
|
4. |
Which of the following statements are correct about static functions?
- Static functions can access only static data.
- Static functions cannot call instance functions.
- It is necessary to initialize static data.
- Instance functions can call static functions and access static data.
- this reference is passed to static functions.
|
A. |
1, 2, 4 |
B. |
2, 3, 5 |
C. |
3, 4 |
D. |
4, 5 |
E. |
None of these |
|
5. |
Which of the following statements is correct about constructors? |
A. |
If we provide a one-argument constructor then the compiler still provides a zero-argument constructor. |
B. |
Static constructors can use optional arguments. |
C. |
Overloaded constructors cannot use optional arguments. |
D. |
If we do not provide a constructor, then the compiler provides a zero-argument constructor. |
Answer: Option D
Solved MCQs From: http://cs-mcqs.blogspot.com
6. |
Which of the following is the correct way to define the constructor(s) of the Sample class if we are to create objects as per the C#.NET code snippet given below?
Sample s1 = new Sample();
Sample s2 = new Sample(9, 5.6f);
|
A. |
public Sample()
{
i = 0;
j = 0.0f;
}
public Sample (int ii, Single jj)
{
i = ii;
j = jj;
}
|
B. |
public Sample (Optional int ii = 0, Optional Single jj = 0.0f)
{
i = ii;
j = jj;
}
|
C. |
public Sample (int ii, Single jj)
{
i = ii;
j = jj;
}
|
D. |
Sample s;
|
E. |
s = new Sample();
|
|
7. |
In which of the following should the methods of a class differ if they are to be treated as overloaded methods?
- Type of arguments
- Return type of methods
- Number of arguments
- Names of methods
- Order of arguments
|
|
8. |
Can static procedures access instance data? |
|
9. |
Which of the following statements are correct about constructors in C#.NET?
- Constructors cannot be overloaded.
- Constructors always have the name same as the name of the class.
- Constructors are never called explicitly.
- Constructors never return any value.
- Constructors allocate space for the object in memory.
|
A. |
1, 3, 5 |
B. |
2, 3, 4 |
C. |
3, 5 |
D. |
4, 5 |
E. |
None of these |
|
10. |
How many times can a constructor be called during lifetime of the object? |
A. |
As many times as we call it. |
B. |
Only once. |
C. |
Depends upon a Project Setting made in Visual Studio.NET. |
D. |
Any number of times before the object gets garbage collected. |
E. |
Any number of times before the object is deleted. |
Answer: Option B
11. |
Is it possible to invoke Garbage Collector explicitly? |
|
12. |
Which of the following statements are correct about the C#.NET code snippet given below?
class Sample
{
static int i;
int j;
public void proc1()
{
i = 11;
j = 22;
}
public static void proc2()
{
i = 1;
j = 2;
}
static Sample()
{
i = 0;
j = 0;
}
}
|
A. |
i cannot be initialized in proc1(). |
B. |
proc1() can initialize i as well as j. |
C. |
j can be initialized in proc2(). |
D. |
The constructor can never be declared as static. |
E. |
proc2() can initialize i as well as j. |
|
13. |
Which of the following statements is correct? |
A. |
There is one garbage collector per program running in memory. |
B. |
There is one common garbage collector for all programs. |
C. |
An object is destroyed by the garbage collector when only one reference refers to it. |
D. |
We have to specifically run the garbage collector after executing Visual Studio.NET. |
|
14. |
Is it possible for you to prevent an object from being created by using zero argument constructor? |
|
15. |
Which of the following statements are correct about static functions? |
A. |
Static functions are invoked using objects of a class. |
B. |
Static functions can access static data as well as instance data. |
C. |
Static functions are outside the class scope. |
D. |
Static functions are invoked using class. |
Answer: Option D
16. |
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class Sample
{
static Sample()
{
Console.Write("Sample class ");
}
public static void Bix1()
{
Console.Write("Bix1 method ");
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample.Bix1();
}
}
}
|
A. |
Sample class Bix1 method |
B. |
Bix1 method |
C. |
Sample class |
D. |
Bix1 method Sample class |
E. |
Sample class Sample class |
|
17. |
Which of the following statements is correct about constructors in C#.NET? |
A. |
A constructor cannot be declared as private. |
B. |
A constructor cannot be overloaded. |
C. |
A constructor can be a static constructor. |
D. |
A constructor cannot access static data. |
E. |
this reference is never passed to a constructor. |
|
18. |
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class Sample
{
public static void fun1()
{
Console.WriteLine("Bix1 method");
}
public void fun2()
{
fun1();
Console.WriteLine("Bix2 method");
}
public void fun2(int i)
{
Console.WriteLine(i);
fun2();
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample s = new Sample();
Sample.fun1();
s.fun2(123);
}
}
}
|
A. |
Bix1 method
123
Bixl method
Bix2 method
|
B. |
Bix1 method
123
Bix2 method
|
C. |
Bix2 method
123
Bix2 method
Bixl method
|
D. |
Bixl method
123
|
E. |
Bix2 method
123
Bixl method
|
Answer: Option A
STRINGS
1. |
Which of the following statements are true about the C#.NET code snippet given below?
String s1, s2;
s1 = "Hi";
s2 = "Hi";
- String objects cannot be created without using new.
- Only one object will get created.
- s1 and s2 both will refer to the same object.
- Two objects will get created, one pointed to by s1 and another pointed to by s2.
- s1 and s2 are references to the same object.
|
|
2. |
Which of the following will be the correct output for the C#.NET code snippet given below?
String s1 = "ALL MEN ARE CREATED EQUAL";
String s2;
s2 = s1.Substring(12, 3);
Console.WriteLine(s2);
|
|
3. |
Which of the following statements will correctly copy the contents of one string into another ? |
A. |
String s1 = "String";
String s2;
s2 = s1;
|
B. |
String s1 = "String" ;
String s2;
s2 = String.Concat(s1, s2);
|
C. |
String s1 = "String";
String s2;
s2 = String.Copy(s1);
|
D. |
String s1 = "String";
String s2;
s2 = s1.Replace();
|
E. |
String s1 = "String";
String s2;
s2 = s2.StringCopy(s1);
|
|
4. |
The string built
using the String class are immutable (unchangeable), whereas, the ones
built- using the StringBuilder class are mutable. |
|
5. |
Which of the following will be the correct output for the C#.NET code snippet given below?
String s1 = "Nagpur";
String s2;
s2 = s1.Insert(6, "Mumbai");
Console.WriteLine(s2);
|
A. |
NagpuMumbair |
B. |
Nagpur Mumbai |
C. |
Mumbai |
D. |
Nagpur |
E. |
NagpurMumbai |
Answer: Option E
6. |
If s1 and s2 are references to two strings, then which of the following is the correct way to compare the two references? |
A. |
s1 is s2 |
B. |
s1 = s2 |
C. |
s1 == s2 |
D. |
strcmp(s1, s2) |
E. |
s1.Equals(s2) |
|
7. |
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class SampleProgram
{
static void Main(string[ ] args)
{
string str= "Hello World!";
Console.WriteLine( String.Compare(str, "Hello World?" ).GetType() );
}
}
}
|
A. |
0 |
B. |
1 |
C. |
String |
D. |
Hello World? |
E. |
System.Int32 |
|
8. |
Which of the following snippets are the correct way to convert a Single into a String?
Single f = 9.8f;
String s;
s = (String) (f);
Single f = 9.8f;
String s;
s = Convert.ToString(f);
Single f = 9.8f;
String s;
s = f.ToString();
Single f = 9.8f;
String s;
s = Clnt(f);
Single f = 9.8f;
String s;
s = CString(f);
|
Answer: Option B
Explanation:
|
9. |
Which of the following will be the correct output for the C#.NET code snippet given below?
String s1="Kicit";
Console.Write(s1.IndexOf('c') + " ");
Console.Write(s1.Length);
|
|
10. |
Which of the following is correct way to convert a String to an int?
String s = "123";
int i;
i = (int)s;
String s = "123";
int i;
i = int.Parse(s);
String s = "123";
int i;
i = Int32.Parse(s);
String s = "123";
int i;
i = Convert.ToInt32(s);
String s = "123";
int i;
i = CInt(s);
|
Answer: Option D
Explanation:
11. |
Which of the following statements about a String is correct? |
A. |
A String is created on the stack. |
B. |
Whether a String is created on the stack or the heap depends on the length of the String. |
C. |
A String is a primitive. |
D. |
A String can be created by using the statement String s1 = new String; |
E. |
A String is created on the heap. |
|
12. |
Which of the following statement is correct about a String in C#.NET? |
A. |
A String is mutable because it can be modified once it has been created. |
B. |
Methods of the String class can be used to modify the string. |
C. |
A number CANNOT be represented in the form of a String. |
D. |
A String has a zero-based index. |
E. |
The System.Array class is used to represent a string. |
|
13. |
Which of the following will be the correct output for the C#.NET code snippet given below?
String s1 = "Five Star";
String s2 = "FIVE STAR";
int c;
c = s1.CompareTo(s2);
Console.WriteLine(c);
|
|
14. |
If s1 and s2
are references to two strings then which of the following are the
correct ways to find whether the contents of the two strings are equal?
if(s1 = s2)
if(s1 == s2)
int c;
c = s1.CompareTo(s2);
if( strcmp(s1, s2) )
if (s1 is s2)
|
|
15. |
Which of the following statements are correct about the String Class in C#.NET?
- Two strings can be concatenated by using an expression of the form s3 = s1 + s2;
- String is a primitive in C#.NET.
- A string built using StringBuilder Class is Mutable.
- A string built using String Class is Immutable.
- Two strings can be concatenated by using an expression of the form s3 = s1&s2;
|
Answer: Option C
16. |
Which of the following statements are correct?
- String is a value type.
- String literals can contain any character literal including escape sequences.
- The equality operators are defined to compare the values of string objects as well as references.
- Attempting to access a character that is outside the bounds of the string results in an IndexOutOfRangeException.
- The contents of a string object can be changed after the object is created.
|
|
17. |
Which of the following is the correct way to find out the index of the second 's' in the string "She sells sea shells on the sea-shore"? |
A. |
String str = "She sells sea shells on the sea-shore";
int i;
i = str.SecondIndexOf("s");
|
B. |
String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.FirstIndexOf("s");
j = str.IndexOf("s", i + 1);
|
C. |
String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.IndexOf("s");
j = str.IndexOf("s", i + 1);
|
D. |
String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.LastIndexOf("s");
j = str.IndexOf("s", i - 1);
|
E. |
String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.IndexOf("S");
j = str.IndexOf("s", i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|