C# - Classes and Objects Questions and Answers
Practice ModeShowing 10 of 37 questions
Q1
Which of the following statements is correct about the C#.NET code snippet given below?
class Student s1, s2; // Here 'Student' is a user-defined class.
s1 = new Student();
s2 = new Student();
Answer: Option C
Q2
Which of the following statements is correct about the C#.NET code snippet given below?
class Sample
{
private int i;
public Single j;
private void DisplayData()
{
Console.WriteLine(i + " " + j);
}
public void ShowData()
{
Console.WriteLine(i + " " + j);
}
}
Answer: Option
Q3
Which of the following statements are correct?
Instance members of a class can be accessed only through an object of that class.
A class can contain only instance data and instance member function.
All objects created from a class will occupy equal number of bytes in memory.
A class can contain Friend functions.
A class is a blueprint or a template according to which objects are created.
Answer: Option A
Q4
Which of the following statements is correct?
Answer: Option D
Q5
Which of the following is the correct way to create an object of the class Sample?
Sample s = new Sample();
Sample s;
Sample s; s = new Sample();
s = new Sample();
Answer: Option A
Q6
The this reference gets created when a member function (non-shared) of a class is called.
Answer: Option A
Q7
Which of the following statements are correct?
Data members ofa class are by default public.
Data members of a class are by default private.
Member functions ofa class are by default public.
A private function of a class can access a public function within the same class.
Member function of a class are by default private.
Answer: Option C
Q8
Which of the following statements are correct about the C#.NET code snippet given below?
sample c;
c = new sample();
It will create an object called sample.
It will create a nameless object of the type sample.
It will create an object of the type sample on the stack.
It will create a reference c on the stack and an object of the type sample on the heap.
It will create an object of the type sample either on the heap or on the stack depending on the size of the object.
Answer: Option B
Q9
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();
Answer: Option A
Q10
Which of the following statements are correct about the this reference?
this reference can be modified in the instance member function of a class.
Static functions of a class never receive the this reference.
Instance member functions of a class always receive a this reference.
this reference continues to exist even after control returns from an instance member function.
While calling an instance member function we are not required to pass the this reference explicitly.
Answer: Option B