Visual Programming MCQs with Answers
Practice important Visual Programming MCQs with answers and explanations.
Multiple Choice Questions
Q201: What is the output of the following C# code? Rectangle rect1 = new Rectangle(); rect1.Width = 1; rect1.Height = 3; Console.writeline("rect1: {0}:{1}", rect1.Width, rect1.Height);
- A: rect1: 0:0
- B: rect1: 1:3
- C: rect1: 3:1
- D: rect1: 0:3
View Answer
B
Q202: What is the purpose of the "this" keyword in an indexer in C#?
- A: To refer to the current instance of the class
- B: To refer to a static member of the class
- C: To refer to a base class
- D: To refer to a nested class
View Answer
A
Q203: Which of the following is NOT a valid parameter type for an indexer in C#?
- A: int
- B: string
- C: enum
- D: class
View Answer
D
Q204: What is the purpose of the "set" accessor in an auto-implemented property in C#?
- A: To return the value of the property
- B: To initialize the value of the property
- C: To assign a value to the property
- D: To delete the value of the property
View Answer
C
Q205: Which of the following can an interface in C# include?
- A: Implementation of methods
- B: Field declarations
- C: Constructors
- D: Method signatures
View Answer
D
Q206: What happens if a struct in C# does not explicitly define a constructor?
- A: It will not compile
- B: The default constructor will initialize all fields to their default values
- C: It will automatically inherit a constructor from a base class
- D: It will create a parameterless constructor
View Answer
B
Q207: Which of the following correctly defines a read-only property in C#?
- A: public int MyProperty { get; set; }
- B: public int MyProperty { get; private set; }
- C: public int MyProperty { set; }
- D: public int MyProperty { get; }
View Answer
D
Q208: How do you initialize a struct using object initialization syntax in C#?
- A: Rectangle rect = new Rectangle(1, 3);
- B: Rectangle rect = new Rectangle();
- C: Rectangle rect = { Width = 1, Height = 3 };
- D: Rectangle rect = new Rectangle { Width = 1, Height = 3 };
View Answer
D
Q209: What is a delegate in C#?
- A: A reference to a method
- B: A reference to a class
- C: An event handler
- D: A variable
View Answer
A
Q210: What is the primary use of delegates in C#?
- A: To store data
- B: To handle exceptions
- C: To reference methods
- D: To define classes
View Answer
C