Online C# Programming Test - C# Programming Test 5

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 is the correct ways to set a value 3.14 in a variable pi such that it cannot be modified?
float pi = 3.14F;
#define pi 3.14F;
const float pi = 3.14F;
const float pi; pi = 3.14F;
pi = 3.14F;
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.

Which of the following statement correctly assigns a value 33 to a variable c?

byte a = 11, b = 22, c;
c = (byte) (a + b);
c = (byte) a + (byte) b;
c = (int) a + (int) b;
c = (int)(a + b);
c = a + b;
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following statements is correct about Bitwise | operator used in C#.NET?
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.
The | operator can be used to put ON a bit.
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following statements are correct about the Bitwise & operator used in C#.NET?
  1. The & operator can be used to Invert a bit.
  2. The & operator can be used to put ON a bit.
  3. The & operator can be used to put OFF a bit.
  4. The & operator can be used to check whether a bit is ON.
  5. The & operator can be used to check whether a bit is OFF.
1, 2, 4
2, 3, 5
3, 4
3, 4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
A function can be used in an expression, whereas a subroutine cannot be.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statements is correct?
There is one garbage collector per program running in memory.
There is one common garbage collector for all programs.
An object is destroyed by the garbage collector when only one reference refers to it.
We have to specifically run the garbage collector after executing Visual Studio.NET.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Can static procedures access instance data?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following statements are correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class index
    {
        protected int count;
        public index()
        {
            count = 0;
        }
    }
    class index1: index
    {
        public void increment()
        {
            count = count +1;
        }
    }
    class MyProgram
    {
        static void Main(string[] args)
        {
            index1 i = new index1(); 
            i.increment(); 
        }
    }
}
  1. count should be declared as public if it is to become available in the inheritance chain.
  2. count should be declared as protected if it is to become available in the inheritance chain.
  3. While constructing an object referred to by i firstly constructor of index class will be called followed by constructor of index1 class.
  4. Constructor of index class does not get inherited in index1 class.
  5. count should be declared as Friend if it is to become available in the inheritance chain.
1, 2, 5
2, 3, 4
3, 5
4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements should be added to the subroutine fun( ) if the C#.NET code snippet given below is to output 9 13?
class BaseClass
{
    protected int i = 13;
}
class Derived: BaseClass
{
    int i = 9; 
    public void fun()
    {
        // [*** Add statement here ***]
    } 
}
Console.WriteLine(base.i + " " + i);
Console.WriteLine(i + " " + base.i);
Console.WriteLine(mybase.i + " " + i);
Console.WriteLine(i + " " + mybase.i);
Console.WriteLine(i + " " + this.i);
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
When would a structure variable get destroyed?
When no reference refers to it, it will get garbage collected.
Depends upon whether it is created using new or without using new.
When it goes out of scope.
Depends upon the Project Settings made in Visual Studio.NET.
Depends upon whether we free it's memory using free() or delete().
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statements are correct about the structure declaration given below?
struct Book
{
    private String name; 
    protected int totalpages; 
    public Single price; 
    public void Showdata()
    {
        Console.WriteLine(name + " " + totalpages + " " + price);
    } 
    Book()
    {
        name = " "; 
        totalpages = 0;
        price = 0.0f; 
    } 
} 
Book b = new Book();
  1. We cannot declare the access modifier of totalpages as protected.
  2. We cannot declare the access modifier of name as private.
  3. We cannot define a zero-argument constructor inside a structure.
  4. We cannot declare the access modifier of price as public.
  5. We can define a Showdata() method inside a structure.
1, 2
1, 3, 5
2, 4
3, 4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Which of the following is the necessary condition for implementing delegates?
Class declaration
Inheritance
Run-time Polymorphism
Exceptions
Compile-time Polymorphism
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following statements are correct about a delegate?
  1. Inheritance is a prerequisite for using delegates.
  2. Delegates are type-safe.
  3. Delegates provide wrappers for function pointers.
  4. The declaration of a delegate must match the signature of the method that we intend to call using it.
  5. Functions called using delegates are always late-bound.
1 and 2 only
1, 2 and 3 only
2, 3 and 4 only
All of the above
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Attributes can be applied to
  1. Method
  2. Class
  3. Assembly
  4. Namespace
  5. Enum
1 and 2 only
1, 2 and 3
4 and 5 only
All of the above
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following statements are valid about generics in .NET Framework?
  1. Generics is a language feature.
  2. We can create a generic class, however, we cannot create a generic interface in C#.NET.
  3. Generics delegates are not allowed in C#.NET.
  4. Generics are useful in collection classes in .NET framework.
  5. None of the above
1 and 2 Only
1, 2 and 3 Only
1 and 4 Only
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 enum used in C#.NET?
  1. Every enum is derived from an Object class.
  2. Every enum is a value type.
  3. There does not exist a way to print an element of an enum as a string.
  4. Every enum is a reference type.
  5. The default underlying datatype of an enum is int.
1, 2, 5
1, 4
3, 5
2, 3, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following statements are correct about an enum used inC#.NET?
  1. To use the keyword enum, we should either use [enum] or System.Enum.
  2. enum is a keyword.
  3. Enum is class declared in System.Type namespace.
  4. Enum is a class declared in the current project's root namespace.
  5. Enum is a class declared in System namespace.
1, 3
2, 4
2, 5
3, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following statements are correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
( 
class Sample
{ 
    private enum color : int
    { 
        red, 
        green, 
        blue
    }
    public void fun()
    {
        Console.WriteLine(color.red); 
    }
}
class Program
{ 
    static void Main(string[ ] args)
    { 
        // Use enum color here
    } 
} 
}
  1. To define a variable of type enum color in Main(), we should use the statement, color c; .
  2. enum color being private it cannot be used in Main().
  3. We must declare enum color as public to be able to use it outside the class Sample.
  4. To define a variable of type enum color in Main(), we should use the statement, Sample.color c; .
  5. We must declare private enum color outside the class to be able to use it in Main().
1, 2, 3
2, 3, 4
3, 4
4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Which of the following statements is correct about the using statement used in C#.NET?
using statement can be placed anywhere in the C#.NET source code file.
It is permitted to define a member at namespace level as a using alias.
A C#.NET source code file can contain any number of using statement.
By using using statement it is possible to create an alias for the namespace but not for the namespace element.
By using using statement it is possible to create an alias for the namespace element but not for the namespace.
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Which of the following is correct way to rewrite the C#.NET code snippet given below?
using Microsoft.VisualBasic;
using System.Windows.Forms;
MessageBox.Show("Wait for a" + ControlChars.CrLf + "miracle");
using System.Windows.Forms;
using CtrlChars = Microsoft.VisualBasic.ControlChars; 
MessageBox.Show("Wait for a" + CrLf + "miracle");
using Microsoft.VisualBasic; 
using System.Windows.Forms; 
CtrlChars = ControlChars;
MessageBox.Show("Wait for a" + CtrlChars.CrLf + "miracle");
using Microsoft.VisualBasic; 
using System.Windows.Forms; 
CtrlChars = ControlChars; 
MessageBox.Show ("Wait for a" + CrLf + "miracle");
using System.Windows.Forms;
using CtrlChars = Microsoft.VisualBasic.ControlChars; 
MessageBox.Show("Wait for a" + CtrlChars.CrLf + "miracle");
Your Answer: Option
(Not Answered)
Correct Answer: Option

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