Welcome to Certifiable, your exam prep headquarters. Here you'll find questions about some of the tricky areas that are fair game for the certification exams. Following the questions, you'll find the correct answers and explanatory text. We change the questions weekly.
This week we continue with questions from topics for Exam 70-176: Designing and Implementing Desktop Applications with Microsoft Visual Basic 6.0. Probably the most important concept a Visual Basic (VB) 6.0 developer needs to understand is the basic operation of COM components, and the three questions below provide a quick quiz on both OOP in general and the Windows implementation of objects in particular.
One book that I've found invaluable in explaining how COM components work is Dan Appleman's Developing COM/ActiveX Components with Visual Basic 6 (ISBN 1562765760). Read this book before you take either Exam 70-175: Designing and Implementing Distributed Applications with Visual Basic 6.0 or Exam 70-176. The book not only has one of the best explanations of the inner workings of COM interfaces, but it also has extensive explanations of each type of component VB 6.0 can create. If you read this book and practice creating and testing different VB 6.0 components, you should have a much easier time passing both the VB 6.0 exams and the upcoming .NET exams when they finally arrive.
How does Visual Basic (VB) provide an object's ability to inherit characteristics of another object?
- Using the InheritFrom statement with the class to inherit from.
- Using the Binary compatibility option and stating which properties and methods to check for in each class.
- Using the Implements statement with the class that contains the interfaces desired and implementing all of the properties and methods.
- VB still doesn't provide this capability.
The Tools ActiveX EXE component contains three SingleUse classes: Widget, Sprocket, and Gear. The MakeSprockets method of the Widget class looks like the following:
Private s2 As Sprocket
Private s3 As Sprocket
Public Sub MakeSprockets()
Set s1 = New Sprocket
Set s2 = New Sprocket
Set s3 = CreateObject(Tools.Sprocket)
Client A executes the following code:
Dim s As Sprocket
Set w = New Widget
Set s = New Sprocket
After the last statement in Client A's code executes, how many instances of the Tools component will be created?
Which statement describes the difference between in-process and out-of-process components?
- In-process components execute in the process space of the calling application; out-of-process components execute in the Windows shared process space.
- In-process components execute in the process space of the calling application; out-of-process components execute in their own distinct process space.
- In-process components execute in the Windows shared process space; out-of-process components execute in their own process space.
- In-process components execute in the VB runtime process space; out-of-process components execute in their own process space.
Answer to Question 1
The correct answer is C—Using the Implements statement with the class that contains the interfaces desired and implementing all of the properties and methods. Object oriented (OO) languages provide polymorphism through inheritance. That is, hypothetical Flea and Tiger classes might both inherit from an Animal class. Each class overrides the Animal class's Bite method with its own bite characteristics. VB provides this capability by letting an object contain multiple interfaces (i.e., your Flea and Tiger classes can implement the Animal class's methods and properties). You can invoke the Bite method on either kind of object, without knowing which kind it is. A flea can nibble its meal, and a tiger can tear at its meal.
References: VB 6.0 Help topics—"Programming with Objects," "Polymorphism," "How Visual Basic Provides Polymorphism"
Answer to Question 2
The correct answer is B—2. Only one instance of the component in which a SingleUse object is defined can serve the object. When Client A executes, the following events occur:
- Client A creates a Widget object, starting an instance of the Tools component.
- Client A calls the MakeSprockets method, which creates three Sprocket objects (the two created with the New operator don't count against the one instance of the Sprocket object the Tools component can create; the one created with the CreateObject function uses up the one instance).
- Client A creates a Sprocket object. Therefore two instances of the Tools component are created.
References: MSDN Library—query for the topic "Scalability Through Multiple Processes: SingleUse Objects"
Answer to Question 3
The correct answer is B—In-process components execute in the process space of the calling application; out-of-process components execute in their own distinct process space. When an application (any .exe file) starts, Windows creates a process space in which the application runs. This process space gets its own memory address space that's inaccessible to other processes. When an application instantiates an object from an in-process component (DLL, OLE custom control—OCX), code executes in the calling application. This calling application is called the client. The in-process component can share the memory address space of the client application.
References: VB 6.0 Help topics—"Creating ActiveX Components," "General Principles of Component Design," "Component Basics," "In-Process and Out-of-Process Components"