Welcome to the Classes and Objects MCQs Page
Dive deep into the fascinating world of Classes and Objects with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Objects, a crucial aspect of C# programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Objects, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# programming.
Check out the MCQs below to embark on an enriching journey through Classes and Objects. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# programming.
Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Objects. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!
Classes and Objects MCQs | Page 3 of 10
Explore more Topics under C# programming
1. Sample s = new Sample();
2. Sample s;
3. Sample s; s = new Sample();
s = new Sample();
namespace CompSciBitsConsoleApplication
{
class Sample
{
int i;
Single j;
public void SetData(int i, Single j)
{
i = i;
j = j;
}
public void Display()
{
Console.WriteLine(i + " " + j);
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample s1 = new Sample();
s1.SetData(10, 5.4f);
s1.Display();
}
}
}
1. Data members ofa class are by default public.
2. Data members of a class are by default private.
3. Member functions of a class are by default public.
4. A private function of a class can access a public function within the same class.
5. Member function of a class are by default private.
namespace CompSciBitsConsoleApplication
{
class Sample
{
public int index;
public int[] arr = new int[10];
public void fun(int i, int val)
{
arr[i] = val;
}
}
class MyProgram
{
static void Main(string[] args)
{
Sample s = new Sample();
s.index = 20;
Sample.fun(1, 5);
s.fun(1, 5);
}
}
}
sample c;
c = new sample();
1. It will create an object called sample.
2. It will create a nameless object of the type sample.
3. It will create an object of the type sample on the stack.
4. It will create a reference c on the stack and an object of the type sample on the heap.
5. It will create an object of the type sample either on the heap or on the stack depending on the size of the object.
int i;
int j = new int();
i = 10;
j = 20;
String str;
str = i.ToString();
str = j.ToString();
1. this reference can be modified in the instance member function of a class.
2. Static functions of a class never receive the this reference.
3. Instance member functions of a class always receive a this reference.
4. this reference continues to exist even after control returns from an instance member function.
5 .While calling an instance member function we are not required to pass the this reference explicitly.
namespace CompSciBitsConsoleApplication
{
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();
}
}
}
Suggested Topics
Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!