Q&A for April 20, 2001
This week we continue with questions from topics for Exam 70-176: Designing and Implementing Desktop Applications with Microsoft Visual Basic 6.0.
April 19, 2001
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.
Questions (April 20, 2001)
Answers (April 20, 2001)
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.
Questions (April 20, 2001)
Question 1
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.
Question 2
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 s1 As SprocketPrivate s2 As SprocketPrivate s3 As SprocketPublic Sub MakeSprockets()Set s1 = New SprocketSet s2 = New SprocketSet s3 = CreateObject(Tools.Sprocket)End Sub
Client A executes the following code:
Dim w As WidgetDim s As SprocketSet w = New Widgetw.MakeSprocketsSet s = New Sprocket
After the last statement in Client A's code executes, how many instances of the Tools component will be created?
1
2
3
4
5
Question 3
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.
Answers (April 20, 2001)
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"
About the Author
You May Also Like