Difficulty: Easy
Correct Answer: A standard module holds global procedures and variables that you do not instantiate, while a class module defines an object type whose instances have their own state and methods.
Explanation:
Introduction / Context:
Many desktop and business applications are built using environments such as Visual Basic, where you can create both standard modules and class modules. Interviewers often ask about the difference between these two constructs because it reveals how well you understand modular programming, global scope and object oriented design. Knowing when to use a module and when to use a class helps you structure code that is maintainable, reusable and testable.
Given Data / Assumptions:
Concept / Approach:
A standard module is typically used to group related global procedures and shared helper functions. Code inside a standard module is usually accessed directly by name, and there is only one shared set of variables at module level. A class module, in contrast, defines a blueprint for objects with properties, methods and events. Each time you create an instance of a class, you get a separate copy of its instance variables. This distinction is essential for encapsulation and object oriented design, where state and behaviour are bundled into objects rather than spread across global modules.
Step-by-Step Solution:
Step 1: Identify that modules are mostly about grouping shared procedures and global data.Step 2: Recognise that classes represent types of objects that can be instantiated multiple times, each with its own state.Step 3: Compare the options and look for the one that clearly states this difference between shared global code and instance based objects.Step 4: Option A says a standard module holds global procedures and variables that you do not instantiate, while a class module defines an object type with instances that have their own state and methods.Step 5: The other options either talk about specific technologies like databases and user interfaces or claim there is no difference, so option A is the correct answer.
Verification / Alternative check:
In practice, when you declare a public function in a standard module, you can call it anywhere in the project without creating an object. When you declare public methods and properties in a class module, you must first create an instance using a constructor or a new keyword. Only then can you access those members. This behaviour confirms that modules and classes play different roles, matching the explanation in option A.
Why Other Options Are Wrong:
Option B ties modules and classes to specific kinds of code such as user interface or database access, which is not a general rule. Option C claims that modules and classes use different compilation models, which is not accurate. Option D suggests there is no difference, which contradicts the design of languages that clearly separate global modules from object definitions.
Common Pitfalls:
A common mistake is to place too much application logic in standard modules, leading to large blocks of global code that are hard to test and reuse. Another pitfall is to create class modules but still treat them like containers for global variables, without leveraging encapsulation. Good design uses standard modules for small sets of shared utilities and class modules for modelling entities, services and user interface components.
Final Answer:
A standard module holds global procedures and variables that you do not instantiate, while a class module defines an object type whose instances have their own state and methods.
Discussion & Comments