Home »
MCQs »
C# MCQs
Which is the correct way to declare an object of the class in C#?
72. Which is the correct way to declare an object of the class in C#?
- Class_Name Object_Name = new Class_Name();
- Class_Name Object_Name;
- new Object_Name as Class_Name();
- Both A and B
Answer: A) Class_Name Object_Name = new Class_Name();
Explanation:
The correct way to declare an object of the class in C# is:
Class_Name Object_Name = new Class_Name();
Consider the below example:
using System;
namespace MyApplication {
class Mobiles {
string brand = "Apple";
static void Main(string[] args) {
Mobiles mobile = new Mobiles();
Console.WriteLine(mobile.brand);
}
}
}
// Output: Apple