AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 10 of 11 questions

1

Which of the following is used to define the member of a class externally?

a

:

b

::

c

#

d

none of the mentioned

correct answer b

Answer: Option (B)

2

What is the most specified using class declaration ?

a

type

b

scope

c

type & scope

d

None of mentioned

correct answer c

General form of class declaration in C# is :
class class_name
{
member variables
variable1;
variable2;
variableN;
method1(parameter_list)
{
method body
}
method2(parameter_list)
{
method body
}
methodN(parameter_list)
{
method body
}
}

3

Which of following statements about objects in “C#” is correct?

a

Everything you use in C# is an object, including Windows Forms and controls

b

Objects have methods and events that allow them to perform actions

c

All objects created from a class will occupy equal number of bytes in memory

d

None of the mentioned

correct answer a,b,c

Answer Options (A), (B) and (C)

By definition.

4

“A mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse.In short it isolates a particular code and data from all other codes and data. A well-defined interface controls the access to that particular code and data.”

a

Abstraction

b

Polymorphism

c

Inheritance

d

Encapsulation

correct answer d

Answer: Option (D)

5

The data members of a class by default are ?

a

protected,public

b

private,public

c

private

d

public

correct answer c

Answer: Option (C)

6

Correct way of declaration of object of the following class is ?
class name

a

name n = new name();

b

n = name();

c

name n = name();

d

n = new name();

correct answer a

Answer: Option (A)

7

What does the following code imply ?
csharp abc;
abc = new charp();

a

Object creation on class csharp

b

Create an object of type csharp on heap or on stack depending on the size of object

c

create a reference c on csharp and an object of type csharp on heap

d

create an object of type csharp on stack

correct answer c

Answer: Option (C)

8

Select output for the following set of code:

class sample

{

     publicint i;

     publicint[] arr =newint[10];

     publicvoid fun(int i, int val)

     {

          arr[i]= val;

     }

}

class Program

{

     staticvoid Main(string[] args)

     {

          sample s =new sample();

          s.i=10;

          sample.fun(1, 5);

          s.fun(1, 5);

          Console.ReadLine();

     }

}

 

 

 

 

a

sample.fun(1, 5) will not work correctly

b

s.i = 10 cannot work as i is ‘public’

c

sample.fun(1, 5) will set value as 5 in arr[1] d) s.fun(1, 5) will work correctly

d

None of the mentioned

correct answer a

An Object reference is required for non static field,method or property.
i.e sample s = new sample();
s.i = 10;
sample.fun(1, 5);
sample.fun(1, 5);
Console.ReadLine();

9

The output of code is ?

class test

{

     publicvoid print()

     {

          Console.WriteLine("Csharp:");

     }

}

class Program

{

     staticvoid Main(string[] args)

     {

          test t;

          t.print();

          Console.ReadLine();

     }

}

 

 

a

Code runs successfully prints nothing

b

Code runs and prints “Csharp”

c

Syntax error as t is unassigned variable which is never used

d

None of above mentioned

correct answer c

object of class test should be declared as test t = new test();
test t = new test();
t.print();
Console.ReadLine();

10

The operator used to access member function of a class?

 

a

:

b

::

c

.

d

#

correct answer c

objectname.function name(actual arguments);

Select a company to compare with

vs

Similar Companies