Online C# Programming Test - C# Programming Test - Random

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 the .NET Framework?
.NET Framework uses DCOM for achieving language interoperability.
.NET Framework is built on the DCOM technology.
.NET Framework uses DCOM for making transition between managed and unmanaged code.
.NET Framework uses DCOM for creating unmanaged applications.
.NET Framework uses COM+ services while creating Distributed Applications.
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following benefits do we get on running managed code under CLR?
  1. Type safety of the code running under CLR is assured.
  2. It is ensured that an application would not access the memory that it is not authorized to access.
  3. It launches separate process for every application running under it.
  4. The resources are Garbage collected.
Only 1 and 2
Only 2, 3 and 4
Only 1, 2 and 4
Only 4
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

4.
Which of the following statements are correct?
  1. The switch statement is a control statement that handles multiple selections and enumerations by passing control to one of the case statements within its body.
  2. The goto statement passes control to the next iteration of the enclosing iteration statement in which it appears.
  3. Branching is performed using jump statements which cause an immediate transfer of the program control.
  4. A common use of continue is to transfer control to a specific switch-case label or the default label in a switch statement.
  5. The do statement executes a statement or a block of statements enclosed in {} repeatedly until a specified expression evaluates to false.
1, 2, 4
1, 3, 5
2, 3, 4
3, 4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following is NOT an Arithmetic operator in C#.NET?
**
+
/
%
*
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
If a procedure fun() is to receive an int, a Single & a double and it is to return a decimal then which of the following is the correct way of defining this procedure?
fun(int i, Single j, double k) decimal 
{ ... }
static decimal fun(int i, Single j, double k) 
{ ... }
fun(int i, Single j, double k) 
{
    ...
    return decimal; 
}
static decimal fun(int i, Single j, double k) decimal 
{ ... }
A procedure can never return a value.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Which of the following statements are correct about constructors in C#.NET?
  1. Constructors cannot be overloaded.
  2. Constructors always have the name same as the name of the class.
  3. Constructors are never called explicitly.
  4. Constructors never return any value.
  5. Constructors allocate space for the object in memory.
1, 3, 5
2, 3, 4
3, 5
4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
In an inheritance chain which of the following members of base class are accessible to the derived class members?
  1. static
  2. protected
  3. private
  4. shared
  5. public
1, 3
2, 5
3, 4
4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class Baseclass
    { 
        public void fun()
        { 
            Console.Write("Base class" + " ");
        } 
    } 
    class Derived1: Baseclass
    { 
        new void fun()
        {
            Console.Write("Derived1 class" + " "); 
        } 
    } 
    class Derived2: Derived1
    { 
        new void fun()
        { 
            Console.Write("Derived2 class" + " ");
        }
    }
    class Program
    { 
        public static void Main(string[ ] args)
        { 
            Derived2 d = new Derived2(); 
            d.fun(); 
        } 
    } 
}
Base class
Derived1 class
Derived2 class
Base class Derived1 class
Base class Derived1 class Derived2 class
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
We can derive a class from a base class even if the base class's source code is not available.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
We can derive from a base class even if it is present in an assembly.

11.
Which of the following statements is correct about the C#.NET code snippet given below?
class Trial
{ 
    int i;
    Decimal d;
}
struct Sample
{
    private int x;
    private Single y;
    private Trial z;
}
Sample ss = new Sample();
ss will be created on the heap.
Trial object referred by z will be created on the stack.
z will be created on the heap.
Both ss and z will be created on the heap.
ss will be created on the stack.
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Which of the following will be the correct output for the C#.NET program given below?
namespace IndiabixConsoleApplication
{ 
    struct Sample
    { 
        public int i;
    }
    class MyProgram
    { 
        static void Main(string[] args)
        {
            Sample x = new Sample(); 
            x.i = 10; 
            fun(ref x); 
            Console.Write(x.i + " ");
        }
        public static void fun(ref Sample y)
        { 
            y.i = 20;
            Console.Write(y.i + " "); 
        } 
    } 
}
20 10
10 20
10 10
20 20
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following statements are correct?
  1. A struct can contain properties.
  2. A struct can contain constructors.
  3. A struct can contain protected data members.
  4. A struct cannot contain methods.
  5. A struct cannot contain constants.
1, 2
3, 4
1, 2, 4
3, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Suppose a Generic class called SortObjects is to be made capable of sorting objects of any type (Integer, Single, Byte etc.). Which of the following programming constructs should be used to implement the comparision function?
Namespace
Interface
Encapsulation
Delegate
Attribute
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following statements is correct about the C#.NET code snippet given below?
enum per
{
    married, 
    unmarried, 
    divorced, 
    spinster
}
per.married = 10; 
Console.WriteLine(per.unmarried);
The program will output a value 11.
The program will output a value 1.
The program will output a value 2.
The program will report an error since an enum element cannot be assigned a value outside the enum declaration.
The enum elements must be declared private.
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Which of the following is the correct output for the C#.NET code snippet given below?
enum color
{
    red,
    green,
    blue 
}
color c; 
c = color.red; 
Console.WriteLine(c);
1
-1
red
0
color.red
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following statements are correct about an enum used in C#.NET?
  1. An enum can be declared inside a class.
  2. An enum can take Single, Double or Decimal values.
  3. An enum can be declared outside a class.
  4. An enum can be declared inside/outside a namespace.
  5. An object can be assigned to an enum variable.
1, 3, 4
2, 5
3, 4
2, 4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

20.
Which of the following statements is correct about an interface used in C#.NET?
If a class implements an interface partially, then it should be an abstract class.
A class cannot implement an interface partially.
An interface can contain static methods.
An interface can contain static data.
Multiple interface inheritance is not allowed.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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