Visual Programming MCQs with Answers
Practice important Visual Programming MCQs with answers and explanations.
Chapter: 7
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
Correct Answer:
B
Chapter: 7
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
Correct Answer:
A
Chapter: 7
Q203:
Which of the following is NOT a valid parameter type for an indexer in C#?
A. int
B. string
C. enum
D. class
Correct Answer:
D
Chapter: 7
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
Correct Answer:
C
Chapter: 7
Q205:
Which of the following can an interface in C# include?
A. Implementation of methods
B. Field declarations
C. Constructors
D. Method signatures
Correct Answer:
D
Chapter: 7
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
Correct Answer:
B
Chapter: 7
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; }
Correct Answer:
D
Chapter: 7
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 };
Correct Answer:
D
Chapter: 8
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
Correct Answer:
A
Chapter: 8
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
Correct Answer:
C
Chapter: 8
Q211:
Which of the following is a correct way to declare a delegate in C#?
A. delegate void myDelegate();
B. public delegate int Comparer(object obj1, object obj2);
C. event delegate int myDelegate();
D. class delegate int Comparer();
Correct Answer:
B
Chapter: 8
Q212:
What is the return type of the delegate method comparefirstnames?
A. void
B. bool
C. int
D. string
Correct Answer:
C
Chapter: 8
Q213:
What is the purpose of the comparefirstnames method in the Name class?
A. To print names
B. To compare first names
C. To initialize objects
D. To sort names
Correct Answer:
B
Chapter: 8
Q214:
How do you instantiate a delegate in C#?
A. Using the new keyword
B. Direct assignment
C. By reference
D. Automatically
Correct Answer:
A
Chapter: 8
Q215:
What does the Sort method in simpledelegate class accept as a parameter?
A. A method name
B. An integer
C. A delegate
D. A string
Correct Answer:
C
Chapter: 8
Q216:
Which of the following is true about events in C#?
A. Events can only be used with forms
B. Events are predefined in .NET
C. Events are always private
D. Events can be activated by firing
Correct Answer:
D
Chapter: 8
Q217:
In C#, which keyword is used to register a delegate with an event?
A. +=
B. -=
C. ==
D. --
Correct Answer:
A
Chapter: 8
Q218:
What is the role of the onclickmeclicked method in the event example?
A. It is a constructor
B. It handles button clicks
C. It creates a new event
D. It initializes the form
Correct Answer:
B
Chapter: 8
Q219:
Which class in C# provides the basic structure for handling exceptions?
A. System.IO
B. System.Exception
C. System.Delegate
D. System.EventHandler
Correct Answer:
B
Chapter: 8
Q220:
What happens if no catch block is found for an exception in C#?
A. The program continues
B. The exception is ignored
C. The program crashes
D. The exception bubbles up the caller stack
Correct Answer:
D