Multiple choice technology programming languages

You develop a Windows-based application that contains a form named ContactABC. You need to write code to initialize all class-level variables in ContactABC as soon as ContactABC is instantiated. You will place your code in a public procedure in the ContactABC class. Which public procedure should you use?

  1. Create

  2. Initialize

  3. Load

  4. New

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The New procedure (constructor) is called when an object is instantiated, making it the ideal place to initialize class-level variables. In VB.NET, Sub New is the constructor that runs automatically when you create an instance using 'New'. Create is not a standard procedure name. Initialize is not a built-in event. Load is a form event that fires after the constructor, when the form is loaded, but variables need initialization earlier. The constructor is the first code that runs when an object is created.

AI explanation

To answer this question, you need to understand the purpose of each public procedure in the ContactABC class. Let's go through each option to understand why it is correct or incorrect:

Option A) Create - This option is incorrect because the "Create" procedure is not a valid public procedure in the ContactABC class.

Option B) Initialize - This option is incorrect because the "Initialize" procedure is not a valid public procedure in the ContactABC class.

Option C) Load - This option is incorrect because the "Load" procedure is typically used to load data or perform initialization tasks when a form is loaded, not when the ContactABC class is instantiated.

Option D) New - This option is correct because the "New" procedure is a valid public procedure in the ContactABC class. It is called when a new instance of the ContactABC class is created, allowing you to initialize class-level variables at that time.

The correct answer is D) New. This option is correct because it allows you to initialize all class-level variables in ContactABC as soon as it is instantiated.