Online C# Programming Test - C# Programming Test 10

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.
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;
}
1 2 3 4 5 6 7 8 9 10
1 2 3 4
0 1 2 3 4 5 6 7 8 9 10
4 5 6 7 8 9 10
4
Your Answer: Option
(Not Answered)
Correct Answer: Option

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);
163 92
92 163
192 63
0 1
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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; 
        }
    }
}
5, 6
5, 36
25, 36
25, 0
5, 0
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
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();
This is a perfectly workable code snippet.
Since int is a primitive, we cannot use new with it.
Since an int is a primitive, we cannot call the method ToString() using it.
i will get created on stack, whereas j will get created on heap.
Both i and j will get created on heap.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

7.
The this reference gets created when a member function (non-shared) of a class is called.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities?
Polymorphism
Containership
Templates
Encapsulation
Inheritance
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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};
intMyArr is a reference to a 2-D jagged array.
The two rows of the jagged array intMyArr are stored in adjacent memory locations.
intMyArr[0] refers to the zeroth 1-D array and intMyArr[1] refers to the first 1-D array.
intMyArr refers to intMyArr[0] and intMyArr[1].
intMyArr refers to intMyArr[1] and intMyArr[2].
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statements will correctly copy the contents of one string into another ?
String s1 = "String";
String s2; 
s2 = s1;
String s1 = "String" ; 
String s2;
s2 = String.Concat(s1, s2);
String s1 = "String"; 
String s2;
s2 = String.Copy(s1);
String s1 = "String"; 
String s2;
s2 = s1.Replace();
String s1 = "String"; 
String s2;
s2 = s2.StringCopy(s1);
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Which of the following statements about a String is correct?
A String is created on the stack.
Whether a String is created on the stack or the heap depends on the length of the String.
A String is a primitive.
A String can be created by using the statement String s1 = new String;
A String is created on the heap.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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); 
        } 
    } 
}
9 9
9 5
5 5
5 9
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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

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);
Dissimilar elements like "hello", 8.2, 5 cannot be stored in the same Stack collection.
Boolean values can never be stored in Stack collection.
In the fourth call to Push(), we should write "b" in place of 'b'.
To store dissimilar elements in a Stack collection, a method PushAnyType() should be used in place of Push().
This is a perfectly workable code.
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following is the Object Oriented way of handling run-time errors?
OnError
HERESULT
Exceptions
Error codes
Setjump and Longjump
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
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 ");
        }
    }
}
It will output: Bad Format
It will output: Remaining program
It will output: Index out of bounds
It will output: Bad Format Remaining program
It will output: Index out of bounds Remaining program
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Which of the following statements is correct about an interface?
One interface can be implemented in another interface.
An interface can be implemented by multiple classes in the same program.
A class that implements an interface can explicitly implement members of that interface.
The functions declared in an interface have a body.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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