Search Placementyogi.com
 

Advanced C# Classes and Objects Objective Questions and Answers

1

Which of the following statement is true regarding "this" keyword (Choose all that apply)

A.

Static functions of a class never receive "this" reference.

B.

Instance member functions of a class always receive "this" reference.

C.

While calling an instance member function it is not required to pass "this" reference explicitly.

D.

"this" reference continues to exist even after control returns from an instance member function.

See Answer & Explanation Lets Discuss
Correct answer is : A,B,C
Explanation

Read C# tutorials to understand "this" keyword.

 
2

Which of the statements will be correct about following C# program?

using System;
namespace PlacementYogi
{
    class Hello
    {
        string name;
        int age;
        public void SetValue(string fName, int age)
        {
            this.name = fName;
            this.age = age;
        }
        public void Display()
        {
            Console.WriteLine("Name: {0}", name);
            Console.WriteLine("Age: {0}", age);
        }
    }
    class MyGreeting
    {
        static void Main(string[] args)
        {
            Hello obj1 = new Hello();
            obj1.SetValue("Krishna", 36);
            Hello obj2 = new Hello();
            obj2.SetValue("Murthi", 46);
            obj1.Display();
            obj2.Display();
        }
    }
}
A.

The code will not compile since we cannot explicitly use "this" keyword.

B.

Using "this" keyword in this program is necessary to properly set values in objects.

C.

The call to SetValue() is wrong since we have not explicitly passed "this" reference to it.

D.

The definition of SetValue() is wrong since we have not explicitly collected "this" reference.

E.

Contents of "this" will be different during each call to SetValue().

See Answer & Explanation Lets Discuss
Correct answer is : E
Explanation

Read C# tutorials to understand "this" keyword.

 
 

Banner to LogicGuns.com

Hide Page Information

Classes in C#, Objects in C# Objective Questions and Answers with Explanation, Interview Questions for Classes in C#, Interview Questions for Objects in C#

Here you can find classes and objects interview questions with answers and explanation.

Why Classes and Objects in C#?

In this section you can learn and practice Classes and Objects(Questions with Answers) to improve your skills in order to face the interview, competitive examination and various entrance test (CAT, GATE, GRE, MAT, Bank Exam etc.) with full confidence.

Where can I get Classes and Objects Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved Classes and Objects questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, fresher can download Classes and Objects quiz questions with answers as PDF files and eBooks.

Where can I get Classes and Objects Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type Classes and Objects questions and answers for interview and entrance examination. Multiple choice and true or false type and yes or no type questions are also provided.