Search Placementyogi.com
 

C# Classes and Objects - Basic Objective Questions

1

Which of the followig statement is true regarding classes and objects? (Choose all that apply)

A.

Class is a blue print that describes how an instance of this class will look in the memory.

B.

Whenever an object of a class is created, it will have instance data and instance member functions of that class.

C.

Garbage collector destroyes the object when it is no longer needed.

D.

Objects are created on managed-heap of memory.

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

No explanation available. Let's Discuss

 
2

How many constructors a C# class can define?

A.

Only one

B.

Only two

C.

Any number

D.

None

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

A constructor looks like a method which has the same name as the class and used to create instance (object) of a class. C# class can define any number of constructors. Every class contains a default constructor initially which does not take any arguments but this default constructor is removed when any custom constructor (defined by programmer) is defined externally.

 
3

Can the method DrawCircle() be overloaded in the following ways in C#?

public int DrawCircle(){.....}
public float DrawCircle(){.....}
A. Yes
B. No
See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

C# provides feature of method overloading that means methods with same name but different types and arguments. Only return type does not decide the method overloading.

 
4

The correct way of creating objects of a class Hello is: (Choose all that apply)

A.

Hello obj1 = new Hello();

B.

Hello obj2; obj = new Hello();

C.

Hello obj3;

D.

Hello obj4 = Hello();

E.

obj5 = new Hello();

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

As discussed in Ques. 1, constructor is used to create an object (instance) of a class and like constructor any number of objects can be created of a class.

To create an object of a class, keyword "new" is used. Options C & D do not use keyword new so get eliminated. Option E does not declare obj5 as Class type (i.e. Hello obj5) so gets eliminted.

 
5

What will be the output of following program?

using System;
namespace PlacementYogiConsoleApplication
{
    class Hello
    {
        int a, b;
        public void SetValue(int a, int b)
        {
            a = a;
            b = b;
        }
        public void DisplayValue()
        {
            Console.WriteLine(a + " " + b);
        }
    }
    class MyGreeting
    {
        static void Main(string[] args)
        {
            Hello obj = new Hello();
            obj.SetValue(1, 2);
            obj.DisplayValue();
        }
    } 
}
A.

1 2

B.

12

C.

0 0

D.

None of the above

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

Default value of integer is 0.

 
 

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.