Home »
Aptitude Questions and Answers »
C# Aptitude Questions and Answers
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?
- A static method of a class can never receive the "this" reference.
- We can modify "this" reference in the instance method of a class.
- When we are calling an instance method of a class, it is not required to pass "this" reference explicitly.
- An instance method of a class is always receiving the "this" reference.
Options:
- Only A
- Only B
- Only C
- A, C and D
Correct answer: 4
A, C and D
In the given statements, A, C and D are correct statements.
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"?
- All Objects of "MyClass" may have the same or different data members.
- All Objects of "MyClass" have the same data members.
- All Objects of "MyClass" will share the same copy of methods.
- Objects of "MyClass" will have the same or different data members depends upon the project setting in Visual Studio.
Options:
- Only A
- Only B
- C and D
- B and C
Correct answer: 4
B and C
In the given statements, B and C are correct statements.
3) What are the correct statements about given code snippets?
Test T = new Test();
- Here we creating object "Test".
- Here we are creating an object of class "Test".
- Here we are creating an object of class "Test" on the stack.
- Here we are creating reference "T" on the stack and object of the type "Test" on the heap.
Options:
- Only A
- Only B
- Only C
- B and D
Correct answer: 4
B and D
In the given statements, B and D are correct statements.
4) What are the correct statements about given code snippets?
Test T1 = new Test();
Test T2 = new Test();
- The value of T1 and T2 will be same exactly.
- Here we create two objects of Test class in the stack.
- The two objects of a class that will always create in adjacent memory locations.
- Here we create two objects of Test class.
Options:
- Only A
- Only B
- Only C
- Only D
Correct answer: 4
Only D
In the given statements, only D is a correct statement.
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);
}
}
- 123, 456
- @123, @456
- Syntax Error
- Runtime Exception
Correct answer: 1
123, 456
The above will print (123, 456) on the console screen.