0% found this document useful (0 votes)
23 views

Tes2 Test2

The code snippet defines a Sample class with multiple overloaded fun2() methods. It then creates an instance of Sample, calls the static fun1() method and instance fun2() method, passing 123 as a parameter. This would result in: Bix1 method 123 Bix2 method Bixl method Being printed out in that order by calling the different fun2() methods.

Uploaded by

noudewatofawaz7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Tes2 Test2

The code snippet defines a Sample class with multiple overloaded fun2() methods. It then creates an instance of Sample, calls the static fun1() method and instance fun2() method, passing 123 as a parameter. This would result in: Bix1 method 123 Bix2 method Bixl method Being printed out in that order by calling the different fun2() methods.

Uploaded by

noudewatofawaz7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1.

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

2. Which of the following statements are correct about the C#.NET code snippet given below? if
(age > 18 || no < 11) a = 25;

A. The condition will get evaluated only evaluates to .

B. The statement will get evaluated any one one of the two conditions is .
C. The statement will get evaluated only both the conditions are .

D. All of these

View Answer up 1 Down -1

Explanation:-

3. Which of the following statement is correct about a String in C#.NET?

A. A number CANNOT be represented in the form of a String.

B. A String has a zero-based index.

C. The class is used to represent a string.

D. A String is mutable because it can be modified once it has been created.

4. Which of the following can be declared in an interface?

A. Properties

B. Methods

C. Events

D. All of the above

5. If Sample class has a Length property with get accessor then which of the following statements will
work correctly?

A.

Sample m = new Sample();

m.Length = 10;

B.

Sample m = new Sample();

m.Length = m.Length + 20;


C.

Sample m = new Sample();

int l;

l = m.Length;

D.

Sample.Length = 20;

E.

Console.WriteLine(Sample.Length);

6.An Account class has a property called accountNo and acc is a reference to a bank object and we want
the C#.NET code snippet given below to work. Which of the following options will ensure this
functionality?

acc.accountNo = 10;

Console.WriteLine(acc.accountNo);

A. Declare accountNo property with both get and set accessors.

B. Declare accountNo property with only get accessor.

C. Declare accountNo property with get, set and normal accessors.

D. Declare accountNo property with only set accessor.

E. None of the above


7.Suppose a Student class has an indexed property. This property is used to set or retrieve values
to/from an array of 5 integers called scores[]. We want the property to report "Invalid Index" message if
the user attempts to exceed the bounds of the array. Which of the following is the correct way to
implement this property?

A.

class Student

int[] scores = new int[5] {3, 2, 4,1, 5};

public int this[ int index ]

set

if (index < 5)

scores[index] = value;

else

Console.WriteLine("Invalid Index");

B.

class Student

int[] scores = new int[5] {3, 2, 4, 1, 5};

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");

C.

class Student

int[] scores = new int[5] {3, 2, 4, 1, 5};

public int this[ int index ]

get

if (index < 5)

return scores[ index ];

else
{

Console.WriteLine("Invalid Index");

return 0;

D.

class Student

int[] scores = new int[5] {3, 2, 4, 1, 5};

public int this[ int index ]

get

if (index < 5)

scores[ index ] = value;

else

Console.WriteLine("Invalid Index");

set

if (index < 5)

return scores[ index ];

else
{

Console.WriteLine("Invalid Index");

return 0;

8. Which of the following statements is correct about properties used in C#.NET?

A. Every property must have a set accessor and a get accessor.

B. Properties cannot be overloaded.

C. Properties of a class are actually methods that work like data members.

D. A property has to be either read only or a write only.

9. Which of the following is the correct way to implement a read only property Length in a Sample class?

A.

class Sample

int len;

public int Length

get

return len;

}
}

B.

class Sample

public int Length

get

return Length;

C.

class Sample

int len;

public int Length

get

return len;

set

len = value;
}

D.

class Sample

int len;

public int Length

Readonly get

return len;

10. Which of the folowing does an indexer allow to index in the same way as an array?

1: A class

2:A property

3:A struct

4:A function

5:An interface
A. 1, 3, 5

B. 2, 4

C. 3, 5

D. 3, 4, 5

11. An Employee class has a property called age and emp is reference to a Employee object and we want
the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this
functionality?

A. Declare age property with only get accessor.

B. Declare age property with only set accessor.

C. Declare age property with both get and set accessors.

D. Declare age property with get, set and normal accessors.

E. None of the above

12. Which of the following statements are correct about data types?

1:If the integer literal exceeds the range of byte, a compilation error will occur.

2:We cannot implicitly convert non-literal numeric types of larger storage size to byte.

3:Byte cannot be implicitly converted to float.

4: A char can be implicitly converted to only int data type.

5: We can cast the integral character codes.

A. 1, 3, 5

B. 2, 4

C. 3, 5

D. 1, 2, 5
13. Which of the following is an 8-byte Integer?

A. Char

B. Long

C. Short

D. Byte

E. Integer

14. Which of the following is NOT an Integer?

A. Char

B. Byte

C. Integer

D. Short

E. Long

15. Which of the following statements is correct?

A. Information is never lost during narrowing conversions.

B. The CInteger() function can be used to convert a Single to an Integer.

C. Widening conversions take place automatically.

D. Assigning an Integer to an Object type is known as Unboxing.

E. 3:14 can be treated as Decimal by using it in the form 3:14F.

16:Which of the following are value types?

1: Integer

2: Array
3: Single

4: String

5: Long

A. 1, 2, 5

B. 1, 3, 5

C. 2, 4

D. 3, 5

17.Which of the following does not store a sign?

A. Short

B. Integer

C. Long

D. Byte

E. Single

19. What is the size of a Decimal?

A. 4 byte

B. 8 byte

C. 16 byte

D. 32 byte

20. What will be the output of the following code snippet when it is executed?

int x = 1;
float y = 1:1f;

short z = 1;

Console.WriteLine((float) x + y * z - (x += (short) y));

A. 0.1

B. 1:0

C. 1:1

D. 11

21Which of the following statements is correct about the C#.NET code snippet given below?

short s1 = 20;

short s2 = 400;

int a;

a = s1 * s2;

A. A value 8000 will be assigned to a.

B. A negative value will be assigned to a.

C. During arithmetic if the result exceeds the high or low value of the range the value wraps
around till the other side of the range.

D. An error is reported as widening conversion cannot takes place.

E. An overflow error will be reported since the result of the multiplication exceeds the range of a
Short Integer.

22. Which of the following is the correct size of a Decimal datatype?

A. 8 Bytes

B. 4 Bytes
C. 10 Bytes

D. 16 Bytes

E. None of the above.

23. Which of the following statements are correct?

1:We can assign values of any type to variables of type object.

2: When a variable of a value type is converted to object, it is said to be unboxed.

3:When a variable of type object is converted to a value type, it is said to be boxed.

4:Boolean variable cannot have a value of null.

5:When a value type is boxed, an entirely new object must be allocated and constructed.

A. 2, 5

B. 1, 5

C. 3, 4

D. 2, 3

24 Which of the following is the correct ways to set a value 3:14 in a variable pi such that it cannot be
modified?

A. float pi = 3:14F;

B. #define pi 3:14F;

C. const float pi = 3:14F;

D. const float pi; pi = 3:14F;

E. pi = 3:14F;
25. Which of the following statements are correct about data types?

1:Each value type has an implicit default constructor that initializes the default value of that type.

2:It is possible for a value type to contain the null value.

3:All value types are derived implicitly from System.ValueType class.

4: It is not essential that local variables in C# must be initialized before being used.

5: Variables of reference types referred to as objects and store references to the actual data.

A. 1, 3, 5

B. 2, 4

C. 3, 5

D. 2, 3, 4

26. Which of the following are the correct way to initialise the variables i and j to a value 10 each?

int i = 10; int j = 10;

int i, j;

i = 10 : j = 10;

int i = 10, j = 10;

int i, j = 10;

int i = j = 10;

A. 2, 4
B. 1, 3

C. 3, 5

D. 4, 5

27. Which of the following statement correctly assigns a value 33 to a variable c?

byte a = 11, b = 22, c;

A. c = (byte) (a + b);

B. c = (byte) a + (byte) b;

C. c = (int) a + (int) b;

D. c = (int)(a + b);

E. c = a + b;

28. Which of the following statements are correct about datatypes in C#.NET?

1:Every datatype is either a value type or a reference type.

2:Value types are always created on the heap.

3:Reference types are always created on the stack.

4:Mapping of every value type to a type in Common Type System facilitates Interoperability in C#.NET.

5:Every reference type gets mapped to a type in Common Type System.

A. 1, 3

B. 2, 5

C. 1, 4

D. 3, 4
29. Which of the following is the correct default value of a Boolean type?

A. 0

B. 1

C. True

D. False

E. -1

30. Which of the following are the correct ways to increment the value of variable a by 1?

1: ++a++;

2: a += 1;

3: a ++ 1;

4: a = a +1;

5: a = +1;

A. 1, 3

B. 2, 4

C. 3, 5

D. 4, 5

E. None of these

31. What will be the output of the C#.NET code snippet given below?

byte b1 = 0xF7;

byte b2 = 0xAB;

byte temp;
temp = (byte)(b1 & b2);

Console.Write (temp + " ");

temp = (byte)(b1^b2);

Console.WriteLine(temp);

A. 163 92

B. 92 163

C. 192 63

D. 01

32. Which of the following is NOT an Arithmetic operator in C#.NET?

A. **

B. +

C. /

D. %

E. *

33. Which of the following are NOT Relational operators in C#.NET?

1: >=

2: !=

3: Not

4: <=

5: <>=

A. 1, 3

B. 2, 4
C. 3, 5

D. 4, 5

E. None of these

34. Which of the following is NOT a Bitwise operator in C#.NET?

A. &

B. |

C. <<

D. ^

E. ~

35. 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.

36. Which of the following is the correct output for the C#.NET code snippet given below?
Console.WriteLine(13 / 2 + " " + 13 % 2);

A. 6.5 1

B. 6.5 0

C. 60

D. 61

E. 6.5 6.5

37. Which of the following statements are correct about the Bitwise & operator used in C#.NET?

1: The & operator can be used to Invert a bit.

2: The & operator can be used to put ON a bit.

3: The & operator can be used to put OFF a bit.

4: The & operator can be used to check whether a bit is ON.

5: 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

38. Which of the following are Logical operators in C#.NET?

1: &&

2: ||

3: !
4: Xor

5: %

A. 1, 2, 3

B. 1, 3, 4

C. 2, 4, 5

D. 3, 4, 5

E. None of these

39. 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("Fourth bit is ON");

B.

if ((n&8) == 8)

Console.WriteLine("Fourth bit is ON");

C.

if ((n ! 8) == 8)

Console.WriteLine("Fourth bit is ON");

D.
if ((n ^ 8) == 8)

Console.WriteLine("Fourth bit is ON");

E.

if ((n ~ 8) == 8)

Console. WriteLine("Fourth bit is ON");

40. What will be the output of the C#.NET code snippet given below?

int num = 1, z = 5;

if (!(num <= 0))

Console.WriteLine( ++num + z++ + " " + ++z );

else

Console.WriteLine( --num + z-- + " " + --z );

A. 56

B. 65

C. 66

D. 77

41.Suppose n is a variable of the type Byte and we wish to put OFF its fourth bit (from right) without
disturbing any other bits. Which of the following statements will do this correctly?

A. n = n && HF7

B. n = n & 16

C. n = n & 0xF7
D. n = n & HexF7

E. n=n&8

42. What will be the output of the C#.NET code snippet given below?

byte b1 = 0xAB;

byte b2 = 0x99;

byte temp;

temp = (byte)~b2;

Console.Write(temp + " ");

temp = (byte)(b1 << b2);

Console.Write (temp + " ");

temp = (byte) (b2 >> 2);

Console.WriteLine(temp);

A. 102 1 38

B. 108 0 32

C. 102 0 38

D. 101

43. Which of the following statements is correct about Bitwise | operator used in C#.NET?

A. The | operator can be used to put OFF a bit.

B. The | operator can be used to Invert a bit.

C. The | operator can be used to check whether a bit is ON.

D. The | operator can be used to check whether a bit is OFF.

E. The | operator can be used to put ON a bit.

44. Which of the following is NOT an Assignment operator in C#.NET?

A. \=
B. /=

C. *=

D. +=

E. %=

45. What will be the output of the C#.NET code snippet given below?

int i, j = 1, k;

for (i = 0; i < 5; i++)

k = j++ + ++j;

Console.Write(k + " ");

A. 8 4 16 12 20

B. 4 8 12 16 20

C. 4 8 16 32 64

D. 2 4 6 8 10

46. What will be the output of the C#.NET code snippet given below?

int a = 10, b = 20, c = 30;

int res = a < b ? a < c ? c : a : b;

Console.WriteLine(res);

A. 10

B. 20
C. 30

D. Compile Error / Syntax Error

47.Which of the following statements are correct about the following code snippet?

int a = 10;

int b = 20;

bool c;

c = !(a > b);

1: There is no error in the code snippet.

2: An error will be reported since ! can work only with an int.

3: A value 1 will be assigned to c.

4: A value True will be assigned to c.

5: A value False will be assigned to c.

A. 1, 3

B. 2, 4

C. 4, 5

D. 1, 4

E. None of these

48. Which of the following statements is correct about Bitwise ^ operator used in C#.NET?

A. The ^ operator can be used to put ON a bit.

B. The ^ operator can be used to put OFF a bit.

C. The ^ operator can be used to Invert a bit.

D. The ^ operator can be used to check whether a bit is ON.


E. The ^ operator can be used to check whether a bit is OFF.

49. Which of the following statements are correct?

1:The conditional operator (?:) returns one of two values depending on the value of a Boolean
expression.

2:The as operator in C#.NET is used to perform conversions between compatible reference types.

3:The &* operator is also used to declare pointer types and to dereference pointers.

4:The -> operator combines pointer dereferencing and member access.

5:In addition to being used to specify the order of operations in an expression, brackets [ ] are used to
specify casts or type conversions.

A. 1, 2, 4

B. 2, 3, 5

C. 3, 4, 5

D. 1, 3, 5

E. None of these

50. Which of the following will be the correct output for the C#.NET program given below?

namespace IndiabixConsoleApplication

class Sample

int i;

Single j;
public void SetData(int i, Single j)

i = i;

j = j;

public void Display()

Console.WriteLine(i + " " + j);

class MyProgram

static void Main(string[ ] args)

Sample s1 = new Sample();

s1:SetData(10, 5:4f);

s1:Display();

A. 00

B. 10 5:4

C. 10 5:400000

D. 10 5

E. None of the above

50. The this reference gets created when a member function (non-shared) of a class is called.

A. True
B. False

51. Which of the following statements is correct about the C#.NET code snippet given below?

namespace IndiabixConsoleApplication

class Sample

public int index;

public int[] arr = new int[10];

public void fun(int i, int val)

arr[i] = val;

class MyProgram

static void Main(string[] args)

Sample s = new Sample();

s.index = 20;

Sample.fun(1, 5);

s.fun(1, 5);

}
A. s.index = 20 will report an error since index is public.

B. The call s.fun(1, 5) will work correctly.

C. Sample.fun(1, 5) will set a value 5 in arr[ 1 ].

D. The call Sample.fun(1, 5) cannot work since fun() is not a shared function.

E. arr being a data member, we cannot declare it as public.

You might also like