adplus-dvertising

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.

frame-decoration

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

Discuss
Answer: (d).Object Oriented Programming paradigm gives equal importance to data and the procedures that work on the data.
Q22.
Which of the following is the correct way to create an object of the class Sample?

1. Sample s = new Sample();
2. Sample s;
3. Sample s; s = new Sample();
s = new Sample();
Discuss
Answer: (a).1, 3
Q23.
Which of the following will be the correct output for the C#.NET program given below?

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(); 
        } 
    } 
}
Discuss
Answer: (a).0 0
Q24.
The this reference gets created when a member function (non-shared) of a class is called.
Discuss
Answer: (a).True
Q25.
Which of the following statements are correct?

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.
Discuss
Answer: (c).2, 4, 5
Q26.
Which of the following statements is correct about the C#.NET code snippet given below?

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); 
        } 
    } 
}
Discuss
Answer: (b).The call s.fun(1, 5) will work correctly.
Q27.
Which of the following statements are correct about the C#.NET code snippet given below?

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.
Discuss
Answer: (b).2, 4
Q28.
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();
Discuss
Answer: (a).This is a perfectly workable code snippet.
Q29.
Which of the following statements are correct about the this reference?

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.
Discuss
Answer: (b).2, 3, 5
Q30.
Which of the following will be the correct output for the C#.NET program given below?

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(); 
        } 
    } 
}
Discuss
Answer: (b).36 5.4

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!