C# Class & Object Aptitude Questions and Answers | Set 2

C# Class & Object Aptitude Questions | Set 2: This section contains aptitude questions and answers on C# Class & Object.
Submitted by Nidhi, on April 12, 2020

1) There are following statements are given below, which of them are correct in about "this" reference in C#.NET?
  1. A static method of a class can never receive the "this" reference.
  2. We can modify "this" reference in the instance method of a class.
  3. When we are calling an instance method of a class, it is not required to pass "this" reference explicitly.
  4. An instance method of a class is always receiving the "this" reference.

Options:

  1. Only A
  2. Only B
  3. Only C
  4. A, C and D

2) There are following statements are given below, which of them are correct in about objects of a user-defined class is known as "MyClass"?
  1. All Objects of "MyClass" may have the same or different data members.
  2. All Objects of "MyClass" have the same data members.
  3. All Objects of "MyClass" will share the same copy of methods.
  4. Objects of "MyClass" will have the same or different data members depends upon the project setting in Visual Studio.

Options:

  1. Only A
  2. Only B
  3. C and D
  4. B and C

3) What are the correct statements about given code snippets?
    Test T = new Test();
  1. Here we creating object "Test".
  2. Here we are creating an object of class "Test".
  3. Here we are creating an object of class "Test" on the stack.
  4. Here we are creating reference "T" on the stack and object of the type "Test" on the heap.

Options:

  1. Only A
  2. Only B
  3. Only C
  4. B and D

4) What are the correct statements about given code snippets?
    Test T1 = new Test();
    Test T2 = new Test();
  1. The value of T1 and T2 will be same exactly.
  2. Here we create two objects of Test class in the stack.
  3. The two objects of a class that will always create in adjacent memory locations.
  4. Here we create two objects of Test class.

Options:

  1. Only A
  2. Only B
  3. Only C
  4. Only D

5) What is the correct output of given code snippets?
using System;

public class Sample
{
    static public void Main()
    {
        int A = 0;
        int B = new int();
        string S1 = "";
        string S2 = "";

        A = 123;
        B = 456;

        S1 = A.ToString();
        S2 = B.ToString();

        Console.WriteLine(S1+", "+S2);
    }
}
  1. 123, 456
  2. @123, @456
  3. Syntax Error
  4. Runtime Exception





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.