C# Programming Questions and Answers
Which of the following is used to define the member of a class externally?
Answer: Option (B)
What is the most specified using class declaration ?
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
}
}
Which of following statements about objects in “C#” is correct?
Answer Options (A), (B) and (C)
By definition.
“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.”
Answer: Option (D)
The data members of a class by default are ?
Answer: Option (C)
Correct way of declaration of object of the following class is ?
class name
Answer: Option (A)
What does the following code imply ?
csharp abc;
abc = new charp();
Answer: Option (C)
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();
}
}
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();
The output of code is ?
class test
{
publicvoid print()
{
Console.WriteLine("Csharp:");
}
}
class Program
{
staticvoid Main(string[] args)
{
test t;
t.print();
Console.ReadLine();
}
}
object of class test should be declared as test t = new test();
test t = new test();
t.print();
Console.ReadLine();
The operator used to access member function of a class?
objectname.function name(actual arguments);