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 are parts of the .NET Framework?
  1. The Common Language Runtime (CLR)
  2. The Framework Class Libraries (FCL)
  3. Microsoft Published Web Services
  4. Applications deployed on IIS
  5. Mobile Applications
Only 1, 2, 3
Only 1, 2
Only 1, 2, 4
Only 4, 5
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

3.

Which 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 value 8000 will be assigned to a.
A negative value will be assigned to a.
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.
An error is reported as widening conversion cannot takes place.
An overflow error will be reported since the result of the multiplication exceeds the range of a Short Integer.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

5.
The C#.NET code snippet given below generates ____ numbers series as output?
int i = 1, j = 1, val;
while (i < 25)
{
    Console.Write(j + " ");
    val = i + j;
    j = i;
    i = val;
}
Prime
Fibonacci
Palindrome
Odd
Even
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
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 + " ");
}
8 4 16 12 20
4 8 12 16 20
4 8 16 32 64
2 4 6 8 10
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Which of the following statements are correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        int i, j; 
        public void SetData(int ii, int jj)
        {
            this.i = ii;
            this.j = jj 
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Sample s1 = new Sample(); 
            s1.SetData(10, 2); 
            Sample s2 = new Sample(); 
            s2.SetData(5, 10); 
        } 
    } 
}
The code will not compile since we cannot explicitly use this.
Using this in this program is necessary to properly set the values in the object.
The call to SetData() is wrong since we have not explicitly passed the this reference to it.
The definition of SetData() is wrong since we have not explicitly collected the this reference.
Contents of this will be different during each call to SetData().
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following is the correct output of the C#.NET code snippet given below?
    int[][] a = new int[2][];
    a[0] = new int[4]{6, 1, 4, 3};
    a[1] = new int[3]{9, 2, 7}; 
    Console.WriteLine(a[1].GetUpperBound(0));
3
4
7
9
2
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements are correct about the C#.NET code snippet given below?
    int[] a = {11, 3, 5, 9, 4}; 
  1. The array elements are created on the stack.
  2. Refernce a is created on the stack.
  3. The array elements are created on the heap.
  4. On declaring the array a new array class is created which is derived from System.Array Class.
  5. Whether the array elements are stored in the stack or heap depends upon the size of the array.
1, 2
2, 3, 4
2, 3, 5
4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Multiple inheritance is different from multiple levels of inheritance.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
Multiple inheritance means deriving a class from more than one classes. On the other hand, multiple levels of inheritance means a class has been derived from a base class and the base class itself has been derived from another base class. Multiple inheritance is not permitted in C#.NET.

11.
It is illegal to make objects of one class as members of another class.
True
False
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()
        {
            Sample x = new Sample(); 
            x.i = 10; 
            fun(x); 
            Console.Write(x.i + " ");
        }
        static void fun(Sample y)
        {
            y.i = 20; 
            Console.Write(y.i + " ");
        } 
    } 
}
10 20
10 10
20 10
20 20
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

14.
Which of the following forms of applying an attribute is correct?
< Serializable() > class sample
{ /* ... */ }
(Serializable()) class sample
{ /* ... */ }
[ Serializable() ] class sample
{ /* ... */ }
Serializablef) class sample
{ /* ... */ }
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following will be the correct output for the C#.NET code snippet given below?
enum color : int
{
    red = -3,
    green,
    blue 
}
Console.Write( (int) color.red + ", "); 
Console.Write( (int) color.green + ", "); 
Console.Write( (int) color.blue );
-3, -2, -1
-3, 0, 1
0, 1, 2
red, green, blue
color.red, color.green, color.blue
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Suppose value of the Capacity property of ArrayList Collection is set to 4. What will be the capacity of the Collection on adding fifth element to it?
4
8
16
32
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following is the correct way to implement a write only property Length in a Sample class?
class Sample
{
    public int Length
    {
        set
        {
            Length = value;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        }
        set
        {
            len = value;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        WriteOnly set
        {
            len = value;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        set
        {
            len = value;
        }
    } 
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following C#.NET code snippets will correctly print "Hello C#.NET"?
import System; 
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main(string[] args)
        { 
            Console.WriteLine("Hello C#.NET");
        } 
    } 
}
using System;
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            WriteLine("Hello C#.NET");
        } 
    } 
}
using System.Console; 
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main (string[ ] args)
        { 
            WriteLine("Hello C#.NET");
        } 
    } 
}
using System;
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main(string[] args)
        { 
            Console.WriteLine("Hello C#.NET");
        }
    }
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Which of the following statement is correct about the C#.NET code snippet given below?
public class Sample
{
    public int x;
    public virtual void fun()
    { }
}
public class DerivedSample : Sample
{
    new public void fun()
    { }
}
DerivedSample class hides the fun() method of base class.
The DerivedSample class version of fun() method gets called using Sample class reference which holds DerivedSample class object.
The code replaces the DerivedSample class version of fun() method with its Sample class version.
It is not possible to hide Sample class version of fun() method without use of new in DerivedSample class.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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