Online C# Programming Test - C# Programming Test 2

Instruction:

  • This is a FREE online test. Beware of scammers who ask for money to attend this test.
  • Total number of questions: 20.
  • Time allotted: 30 minutes.
  • Each question carries 1 mark; there are no negative marks.
  • DO NOT refresh the page.
  • All the best!

Marks : 2/20


Total number of questions
20
Number of answered questions
0
Number of unanswered questions
20
Test Review : View answers and explanation for this test.

1.
Which of the following statements is correct about Managed Code?
Managed code is the code that is compiled by the JIT compilers.
Managed code is the code where resources are Garbage Collected.
Managed code is the code that runs on top of Windows.
Managed code is the code that is written to target the services of the CLR.
Managed code is the code that can run on top of Linux.
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following is the root of the .NET type hierarchy?
System.Object
System.Type
System.Base
System.Parent
System.Root
Your Answer: Option
(Not Answered)
Correct Answer: Option

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);
1, 3
1 Only
2, 3
4 Only
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

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.
1, 4, 5
2, 4
1, 3, 4
2, 3, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following statements is correct about Bitwise ^ operator used in C#.NET?
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 Invert 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.
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
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?
n = n && HF7
n = n & 16
n = n & 0xF7
n = n & HexF7
n = n & 8
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
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);
102 1 38
108 0 32
102 0 38
1 0 1
Your Answer: Option
(Not Answered)
Correct Answer: Option

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();
Contents of s1 and s2 will be exactly same.
The two objects will get created on the stack.
Contents of the two objects created will be exactly same.
The two objects will always be created in adjacent memory locations.
We should use delete() to delete the two objects from memory.
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
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.
1, 3
2, 4
4, 5
3, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
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.
1, 4
2, 3, 5
3, 4
2, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
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();
The structure variable b will be created on the heap.
We can add a zero-argument constructor to the above structure.
When the program terminates, variable b will get garbage collected.
The structure variable b will be created on the stack.
We can inherit a new structure from struct Book.
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
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.
1, 2, 4
2, 3, 5
2, 4
1, 3
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
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();
20 bytes
12 bytes
8 bytes
16 bytes
24 bytes
Your Answer: Option
(Not Answered)
Correct Answer: Option

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 !");
    }
}
delegate void del(int i);
Sample s = new Sample();
del d = new del(ref s.MyFun);
d(10, 1.1f);
delegate void del(int i, Single j);
del d;
Sample s = new Sample();
d = new del(ref s.MyFun);
d(10, 1.1f);
Sample s = new Sample();
delegate void d = new del(ref MyFun);
d(10, 1.1f);
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

15.
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);
IEnumerable e;
e = st.GetEnumerator(); 
while (e.MoveNext())
Console.WriteLine(e.Current);
IEnumerator e;
e = st.GetEnumerable(); 
while (e.MoveNext())
Console.WriteLine(e.Current);
IEnumerator e;
e = st.GetEnumerator(); 
while (e.MoveNext()) 
Console.WriteLine(e.Current);
IEnumerator e;
e = Stack.GetEnumerator(); 
while (e.MoveNext()) 
Console.WriteLine(e.Current);
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
In a HashTable Key cannot be null, but Value can be.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

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
1, 2, 3
3, 5
2, 4
2, 3, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following is the correct implementation of the interface given below?
interface IMyInterface
{ 
    double MyFun(Single i);
}
class MyClass
{
    double MyFun(Single i) as IMyInterface.MyFun
    {
        // Some code
    }
}
class MyClass 
{
    MyFun (Single i) As Double
    {
        // Some code
    } 
}
class MyClass: implements IMyInterface
{
    double fun(Single si) implements IMyInterface.MyFun()
    {
        //Some code
    } 
}
class MyClass: IMyInterface
{
    double IMyInterface.MyFun(Single i)
    {
        // Some code
    } 
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

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
    } 
}
Class MyClass is an abstract class.
Class MyClass cannot contain instance data.
Class MyClass fully implements the interface IMyInterface.
Interface IMyInterface should be inherited from the Object class.
The compiler will report an error since the interface IMyInterface is only partially implemented.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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(); 
}
Properties cannot be declared inside an interface.
This is a perfectly workable interface.
The properties in the interface must have a body.
Subroutine in the interface must have a body.
Functions cannot be declared inside an interface.
Your Answer: Option
(Not Answered)
Correct Answer: Option

*** END OF THE TEST ***
Time Left: 00:29:56
Post your test result / feedback here: