Online C# Programming Test - C# Programming Test 10



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.

What will be the output of the code snippet given below?

int i;
for(i = 0; i<=10; i++)
{
    if(i == 4)
    {
        Console.Write(i + " "); continue;
    }
    else if (i != 4)
        Console.Write(i + " "); else
    break;
}

A.
1 2 3 4 5 6 7 8 9 10
B.
1 2 3 4
C.
0 1 2 3 4 5 6 7 8 9 10
D.
4 5 6 7 8 9 10
E.
4

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum


2.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Operators

Discuss about this problem : Discuss in Forum


3.

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

namespace IndiabixConsoleApplication
{ 
    class SampleProgram
    { 
        static void Main(string[ ] args)
        { 
            int a = 5;
            int s = 0, c = 0; 
            s, c = fun(a); 
            Console.WriteLine(s +" " + c) ;
        }
        static int fun(int x)
        {
            int ss, cc;
            ss = x * x; cc = x * x * x; 
            return ss, cc;
        } 
    } 
}
  1. An error will be reported in the statement s, c = fun(a); since multiple values returned from a function cannot be collected in this manner.
  2. It will output 25 125.
  3. It will output 25 0.
  4. It will output 0 125.
  5. An error will be reported in the statement return ss, cc; since a function cannot return multiple values.

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Functions and Subroutines

Discuss about this problem : Discuss in Forum


4.

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

namespace IndiabixConsoleApplication
{
    class SampleProgram
    {
        static void Main(string[ ] args)
        {
            int i = 5;
            int j;
            fun1(ref i);
            fun2(out j);
            Console.WriteLine(i + ", " + j);
        }
        static void funl(ref int x)
        {
            x = x * x;
        }
        static void fun2(out int x)
        {
            x = 6; 
            x = x * x; 
        }
    }
}

A.
5, 6
B.
5, 36
C.
25, 36
D.
25, 0
E.
5, 0

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Functions and Subroutines

Discuss about this problem : Discuss in Forum


5.

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

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Classes and Objects

Discuss about this problem : Discuss in Forum


6.

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

int i;
int j = new int();
i = 10;
j = 20; 
String str; 
str = i.ToString(); 
str = j.ToString();

A.
This is a perfectly workable code snippet.
B.
Since int is a primitive, we cannot use new with it.
C.
Since an int is a primitive, we cannot call the method ToString() using it.
D.
i will get created on stack, whereas j will get created on heap.
E.
Both i and j will get created on heap.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Classes and Objects

Discuss about this problem : Discuss in Forum


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

A.
The code will not compile since we cannot explicitly use this.
B.
Using this in this program is necessary to properly set the values in the object.
C.
The call to SetData() is wrong since we have not explicitly passed the this reference to it.
D.
The definition of SetData() is wrong since we have not explicitly collected the this reference.
E.
Contents of this will be different during each call to SetData().

Your Answer: Option (Not Answered)

Correct Answer: Option E

Learn more problems on : Classes and Objects

Discuss about this problem : Discuss in Forum


8.

Which of the following can be facilitated by the Inheritance mechanism?

  1. Use the existing functionality of base class.
  2. Overrride the existing functionality of base class.
  3. Implement new functionality in the derived class.
  4. Implement polymorphic behaviour.
  5. Implement containership.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Inheritance

Discuss about this problem : Discuss in Forum


9.

Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities?

A.
Polymorphism
B.
Containership
C.
Templates
D.
Encapsulation
E.
Inheritance

Your Answer: Option (Not Answered)

Correct Answer: Option E

Learn more problems on : Inheritance

Discuss about this problem : Discuss in Forum


10.

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

   int[][]intMyArr = new int[2][]; 
   intMyArr[0] = new int[4]{6, 1, 4, 3}; 
   intMyArr[1] = new int[3]{9, 2, 7};

A.
intMyArr is a reference to a 2-D jagged array.
B.
The two rows of the jagged array intMyArr are stored in adjacent memory locations.
C.
intMyArr[0] refers to the zeroth 1-D array and intMyArr[1] refers to the first 1-D array.
D.
intMyArr refers to intMyArr[0] and intMyArr[1].
E.
intMyArr refers to intMyArr[1] and intMyArr[2].

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum


11.

Which of the following statements will correctly copy the contents of one string into another ?

A.
String s1 = "String";
String s2; 
s2 = s1;
B.
String s1 = "String" ; 
String s2;
s2 = String.Concat(s1, s2);
C.
String s1 = "String"; 
String s2;
s2 = String.Copy(s1);
D.
String s1 = "String"; 
String s2;
s2 = s1.Replace();
E.
String s1 = "String"; 
String s2;
s2 = s2.StringCopy(s1);

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum


12.

Which of the following statements about a String is correct?

A.
A String is created on the stack.
B.
Whether a String is created on the stack or the heap depends on the length of the String.
C.
A String is a primitive.
D.
A String can be created by using the statement String s1 = new String;
E.
A String is created on the heap.

Your Answer: Option (Not Answered)

Correct Answer: Option E

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum


13.

Which of the following will be the correct output for the program given below?

namespace IndiabixConsoleApplication
{ 
    struct Sample
    {
        public int i;
    }
    class MyProgram
    { 
        static void Main(string[] args)
        {
            Sample x = new Sample();
            Sample y;
            x.i = 9;
            y = x;
            y.i = 5;
            Console.WriteLine(x.i + " " + y.i); 
        } 
    } 
}

A.
9 9
B.
9 5
C.
5 5
D.
5 9
E.
None of the above

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 are correct ways to pass a parameter to an attribute?

  1. By value
  2. By reference
  3. By address
  4. By position
  5. By name

A.
1, 2
B.
1, 2, 3
C.
4, 5
D.
All of the above

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Attributes

Discuss about this problem : Discuss in Forum


15.

Which of the following statements are correct about inspecting an attribute in C#.NET?

  1. An attribute can be inspected at link-time.
  2. An attribute can be inspected at compile-time.
  3. An attribute can be inspected at run-time.
  4. An attribute can be inspected at design-time.

A.
1, 2
B.
3, 4
C.
1, 3, 4
D.
All of the above
E.
None of the above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Attributes

Discuss about this problem : Discuss in Forum


16.

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

Stack st = new Stack();
st.Push("hello");
st.Push(8.2);
st.Push(5);
st.Push('b');
st.Push(true);

A.
Dissimilar elements like "hello", 8.2, 5 cannot be stored in the same Stack collection.
B.
Boolean values can never be stored in Stack collection.
C.
In the fourth call to Push(), we should write "b" in place of 'b'.
D.
To store dissimilar elements in a Stack collection, a method PushAnyType() should be used in place of Push().
E.
This is a perfectly workable code.

Your Answer: Option (Not Answered)

Correct Answer: Option E

Learn more problems on : Collection Classes

Discuss about this problem : Discuss in Forum


17.

Which of the following is the Object Oriented way of handling run-time errors?

A.
OnError
B.
HERESULT
C.
Exceptions
D.
Error codes
E.
Setjump and Longjump

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Exception Handling

Discuss about this problem : Discuss in Forum


18.

Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.

A.
True
B.
False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Exception Handling

Discuss about this problem : Discuss in Forum


19.

Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?

using System;
namespace IndiabixConsoleApplication
{
    class MyProgram
    {
        static void Main(string[] args)
        {
            int index; 
            int val = 55; 
            int[] a = new int[5]; 
            try
            {
                Console.Write("Enter a number: ");
                index = Convert.ToInt32(Console.ReadLine());
                a[index] = val;
            }
            catch(FormatException e)
            {
                Console.Write("Bad Format ");
            }
            catch(IndexOutOfRangeException e)
            {
                Console.Write("Index out of bounds ");
            }
            Console.Write("Remaining program ");
        }
    }
}

A.
It will output: Bad Format
B.
It will output: Remaining program
C.
It will output: Index out of bounds
D.
It will output: Bad Format Remaining program
E.
It will output: Index out of bounds Remaining program

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Exception Handling

Discuss about this problem : Discuss in Forum


20.

Which of the following statements is correct about an interface?

A.
One interface can be implemented in another interface.
B.
An interface can be implemented by multiple classes in the same program.
C.
A class that implements an interface can explicitly implement members of that interface.
D.
The functions declared in an interface have a body.

Your Answer: Option (Not Answered)

Correct Answer: Option C

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.