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

2.
Which of the following statements are correct about the C#.NET code snippet given below?
if (age > 18 || no < 11)
    a = 25;
  1. The condition no < 11 will get evaluated only if age > 18 evaluates to False.
  2. The condition no < 11 will get evaluated if age > 18 evaluates to True.
  3. The statement a = 25 will get evaluated if any one one of the two conditions is True.
  4. || is known as a short circuiting logical operator.
  5. The statement a = 25 will get evaluated only if both the conditions are True.
1, 4, 5
2, 4
1, 3, 4
2, 3, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
What will be the output of the C#.NET code snippet given below?
int a = 10, b = 20, c = 30; 
int res = a < b ? a < c ? c : a : b; 
Console.WriteLine(res);
10
20
30
Compile Error / Syntax Error
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

5.
A function returns a value, whereas a subroutine cannot return a value.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
How many values is a function capable of returning?
1
0
Depends upon how many params arguments does it use.
Any number of values.
Depends upon how many ref arguments does it use.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
If a function 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 function?
decimal static fun(int i, Single j, double k)
{ ... }
decimal fun(int i, Single j, double k)
{ ... }
static decimal fun(int i, Single j, double k)
{ ... }
static decimal fun(int i, Single j, double k) decimal
{ ... }
static fun(int i, Single j, double k)
{ 
    ... 
    return decimal;
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following will be the correct output for the C#.NET program given below?
namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        int i; 
        Single j; 
        public void SetData(int i, Single j)
        { 
            this.i = i; 
            this.j = j;
        }
        public void Display()
        { 
            Console.WriteLine(i + " " + j);
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        {
            Sample s1 = new Sample(); 
            s1.SetData(36, 5.4f); 
            s1.Display(); 
        } 
    } 
}
0 0.0
36 5.4
36 5.400000
36 5
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements is correct?
Procedural Programming paradigm is different than structured programming paradigm.
Object Oriented Programming paradigm stresses on dividing the logic into smaller parts and writing procedures for each part.
Classes and objects are corner stones of structured programming paradigm.
Object Oriented Programming paradigm gives equal importance to data and the procedures that work on the data.
C#.NET is a structured programming language.
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following statements are correct about the C#.NET code snippet given below?
class Sample
{
    static int i;
    int j;
    public void proc1()
    {
        i = 11; 
        j = 22;
    }
    public static void proc2()
    {
        i = 1;
        j = 2;
    }
    static Sample()
    {
        i = 0; 
        j = 0;
    }
}
i cannot be initialized in proc1().
proc1() can initialize i as well as j.
j can be initialized in proc2().
The constructor can never be declared as static.
proc2() can initialize i as well as j.
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statements is correct about constructors?
If we provide a one-argument constructor then the compiler still provides a zero-argument constructor.
Static constructors can use optional arguments.
Overloaded constructors cannot use optional arguments.
If we do not provide a constructor, then the compiler provides a zero-argument constructor.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

13.
Which of the following statements is correct about the C#.NET code snippet given below?
    int[] intMyArr = {11, 3, 5, 9, 4}; 
intMyArr is a reference to an object of System.Array Class.
intMyArr is a reference to an object of a class that the compiler derives from System.Array Class.
intMyArr is a reference to an array of integers.
intMyArr is a reference to an object created on the stack.
intMyArr is a reference to the array created on the stack.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Which of the following is the correct way to define a variable of the type struct Emp declared below?
struct Emp
{
    private String name; 
    private int age; 
    private Single sal;
}
  1. Emp e(); e = new Emp();
  2. Emp e = new Emp;
  3. Emp e; e = new Emp;
  4. Emp e = new Emp();
  5. Emp e;
1, 3
2, 5
4, 5
1, 2, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following is correct ways of applying an attribute?
[WebService (Name = "IndiaBIX", Description = "BIX WebService")] 
class AuthenticationService: WebService
{ /* .... */}
<WebService ( Name : "IndiaBIX", Description : "BIX WebService" )> 
class AuthenticationService: inherits WebService
{ /* .... */}
<WebService ( Name = "IndiaBIX", Description = "BIX WebService" )> 
class AuthenticationService: extends WebService
{ /* .... */}
[WebService ( Name := "IndiaBIX", Description := "BIX WebService")] 
class AuthenticationService: inherits WebService
{ /* .... */}
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
It possible to create a custom attribute that can be applied only to specific programming element(s) like ____ .
Classes
Methods
Classes and Methods
Classes, Methods and Member-Variables
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this functionality?
Declare age property with only get accessor.
Declare age property with only set accessor.
Declare age property with both get and set accessors.
Declare age property with get, set and normal accessors.
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
An Account class has a property called accountNo and acc is a reference to a bank object and we want the C#.NET code snippet given below to work. Which of the following options will ensure this functionality?
acc.accountNo = 10; 
Console.WriteLine(acc.accountNo);
Declare accountNo property with both get and set accessors.
Declare accountNo property with only get accessor.
Declare accountNo property with get, set and normal accessors.
Declare accountNo property with only set accessor.
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Which of the following keyword is used to overload user-defined types by defining static member functions?
op
opoverload
operator
operatoroverload
udoperator
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Which of the following statements is correct about an interface used in C#.NET?
One class can implement only one interface.
In a program if one class implements an interface then no other class in the same program can implement this interface.
From two base interfaces a new interface cannot be inherited.
Properties can be declared inside an interface.
Interfaces cannot be inherited.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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