Online C# Programming Test - C# Programming Test 2



Loading...  Loading Test...

Instruction:

  • This is a FREE online test. DO NOT pay money to anyone to attend this test.
  • Total number of questions : 20.
  • Time alloted : 30 minutes.
  • Each question carry 1 mark, no negative marks.
  • DO NOT refresh the page.
  • All the best :-).


1.

Which of the following statements is correct about Managed Code?

A.
Managed code is the code that is compiled by the JIT compilers.
B.
Managed code is the code where resources are Garbage Collected.
C.
Managed code is the code that runs on top of Windows.
D.
Managed code is the code that is written to target the services of the CLR.
E.
Managed code is the code that can run on top of Linux.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : .NET Framework

Discuss about this problem : Discuss in Forum


2.

Which of the following is the root of the .NET type hierarchy?

A.
System.Object
B.
System.Type
C.
System.Base
D.
System.Parent
E.
System.Root

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : .NET Framework

Discuss about this problem : Discuss in Forum


3.

Which of the following code snippets are the correct way to determine whether a is Odd or Even?

  1. int a;
    String res; 
    if (a % 2 == 0)
        res = "Even"; 
    else 
        res = "Odd";
  2. int a; 
    String res; 
    if (a Mod 2 == 0) 
        res = "Even"; 
    else
        res = "Odd";
  3. int a;
    Console.WriteLine(a Mod 2 == 0 ? "Even": "Odd");
  4. int a; 
    String res;
    a % 2 == 0 ? res = "Even" : res = "Odd";
    Console.WriteLine(res);

A.
1, 3
B.
1 Only
C.
2, 3
D.
4 Only
E.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


4.

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

if (age > 18 || no < 11)
    a = 25;
  1. The condition no < 11 will get evaluated only if age > 18 evaluates to False.
  2. The condition no < 11 will get evaluated if age > 18 evaluates to True.
  3. The statement a = 25 will get evaluated if any one one of the two conditions is True.
  4. || is known as a short circuiting logical operator.
  5. The statement a = 25 will get evaluated only if both the conditions are True.

A.
1, 4, 5
B.
2, 4
C.
1, 3, 4
D.
2, 3, 5
E.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


5.

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Operators

Discuss about this problem : Discuss in Forum


6.

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.
1 0 1

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Operators

Discuss about this problem : Discuss in Forum


7.

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.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Operators

Discuss about this problem : Discuss in Forum


8.

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

class Student s1, s2; // Here 'Student' is a user-defined class.
s1 = new Student(); 
s2 = new Student();

A.
Contents of s1 and s2 will be exactly same.
B.
The two objects will get created on the stack.
C.
Contents of the two objects created will be exactly same.
D.
The two objects will always be created in adjacent memory locations.
E.
We should use delete() to delete the two objects from memory.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Classes and Objects

Discuss about this problem : Discuss in Forum


9.

Which of the following statements are correct about the this reference?

  1. this reference can be modified in the instance member function of a class.
  2. Static functions of a class never receive the this reference.
  3. Instance member functions of a class always receive a this reference.
  4. this reference continues to exist even after control returns from an instance member function.
  5. While calling an instance member function we are not required to pass the this reference explicitly.

A.
1, 4
B.
2, 3, 5
C.
3, 4
D.
2, 5
E.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Classes and Objects

Discuss about this problem : Discuss in Forum


10.

Which of the following statements are correct about objects of a user-defined class called Sample?

  1. All objects of Sample class will always have exactly same data.
  2. Objects of Sample class may have same or different data.
  3. Whether objects of Sample class will have same or different data depends upon a Project Setting made in Visual Studio.NET.
  4. Conceptually, each object of Sample class will have instance data and instance member functions of the Sample class.
  5. All objects of Sample class will share one copy of member functions.

A.
1, 3
B.
2, 4
C.
4, 5
D.
3, 5
E.
None of these

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Classes and Objects

Discuss about this problem : Discuss in Forum


11.

How many bytes will the structure variable samp occupy in memory if it is defined as shown below?

class Trial
{ 
    int i; 
    Decimal d;
}
struct Sample
{
    private int x; 
    private Single y; 
    private Trial z;
}
Sample samp = new Sample();

A.
20 bytes
B.
12 bytes
C.
8 bytes
D.
16 bytes
E.
24 bytes

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures

Discuss about this problem : Discuss in Forum


12.

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

struct Book
{
    private String name; 
    private int noofpages; 
    private Single price;
}
Book b = new Book();

A.
The structure variable b will be created on the heap.
B.
We can add a zero-argument constructor to the above structure.
C.
When the program terminates, variable b will get garbage collected.
D.
The structure variable b will be created on the stack.
E.
We can inherit a new structure from struct Book.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Structures

Discuss about this problem : Discuss in Forum


13.

Which of the following statements are correct about Structures used in C#.NET?

  1. A Structure can be declared within a procedure.
  2. Structs can implement an interface but they cannot inherit from another struct.
  3. struct members cannot be declared as protected.
  4. A Structure can be empty.
  5. It is an error to initialize an instance field in a struct.

A.
1, 2, 4
B.
2, 3, 5
C.
2, 4
D.
1, 3

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Structures

Discuss about this problem : Discuss in Forum


14.

Which of the following is the correct way to call subroutine MyFun() of the Sample class given below?

class Sample
{
    public void MyFun(int i, Single j)
    {
        Console.WriteLine("Welcome to IndiaBIX !");
    }
}

A.
delegate void del(int i);
Sample s = new Sample();
del d = new del(ref s.MyFun);
d(10, 1.1f);
B.
delegate void del(int i, Single j);
del d;
Sample s = new Sample();
d = new del(ref s.MyFun);
d(10, 1.1f);
C.
Sample s = new Sample();
delegate void d = new del(ref MyFun);
d(10, 1.1f);
D.
delegate void del(int i, Single]);
Sample s = new Sample();
del = new delegate(ref MyFun);
del(10, 1.1f);

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Delegates

Discuss about this problem : Discuss in Forum


15.

In a HashTable Key cannot be null, but Value can be.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Collection Classes

Discuss about this problem : Discuss in Forum


16.

Which of the following is the correct way to access all elements of the Stack collection created using the C#.NET code snippet given below?

Stack st = new Stack();
st.Push(11);
st.Push(22);
st.Push(-53);
st.Push(33);
st.Push(66);

A.
IEnumerable e;
e = st.GetEnumerator(); 
while (e.MoveNext())
Console.WriteLine(e.Current);
B.
IEnumerator e;
e = st.GetEnumerable(); 
while (e.MoveNext())
Console.WriteLine(e.Current);
C.
IEnumerator e;
e = st.GetEnumerator(); 
while (e.MoveNext()) 
Console.WriteLine(e.Current);
D.
IEnumerator e;
e = Stack.GetEnumerator(); 
while (e.MoveNext()) 
Console.WriteLine(e.Current);

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Collection Classes

Discuss about this problem : Discuss in Forum


17.

Which of the following can be declared as a virtual in a class?

  1. Methods
  2. Properties
  3. Events
  4. Fields
  5. Static fields

A.
1, 2, 3
B.
3, 5
C.
2, 4
D.
2, 3, 5

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Polymorphism

Discuss about this problem : Discuss in Forum


18.

Which of the following is the correct implementation of the interface given below?

interface IMyInterface
{ 
    double MyFun(Single i);
}

A.
class MyClass
{
    double MyFun(Single i) as IMyInterface.MyFun
    {
        // Some code
    }
}
B.
class MyClass 
{
    MyFun (Single i) As Double
    {
        // Some code
    } 
}
C.
class MyClass: implements IMyInterface
{
    double fun(Single si) implements IMyInterface.MyFun()
    {
        //Some code
    } 
}
D.
class MyClass: IMyInterface
{
    double IMyInterface.MyFun(Single i)
    {
        // Some code
    } 
}

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Interfaces

Discuss about this problem : Discuss in Forum


19.

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

interface IMyInterface 
{
    void fun1(); 
    void fun2();
}
class MyClass: IMyInterface
{ 
    private int i; 
    void IMyInterface.fun1()
    { 
        // Some code
    } 
}

A.
Class MyClass is an abstract class.
B.
Class MyClass cannot contain instance data.
C.
Class MyClass fully implements the interface IMyInterface.
D.
Interface IMyInterface should be inherited from the Object class.
E.
The compiler will report an error since the interface IMyInterface is only partially implemented.

Your Answer: Option (Not Answered)

Correct Answer: Option E

Learn more problems on : Interfaces

Discuss about this problem : Discuss in Forum


20.

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

interface IPerson
{ 
    String FirstName
    { 
        get; 
        set;
    }
    String LastName
    {
        get; 
        set;
    }
    void Print(); 
    void Stock(); 
    int Fun(); 
}

A.
Properties cannot be declared inside an interface.
B.
This is a perfectly workable interface.
C.
The properties in the interface must have a body.
D.
Subroutine in the interface must have a body.
E.
Functions cannot be declared inside an interface.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Interfaces

Discuss about this problem : Discuss in Forum


Submit your test now to view the Results and Statistics with answer explanation.