Workshop


Quiz

1.

To create objects, you must first create a template. This template is called a __________.

2.

One of the primary benefits of object-oriented programming is that objects contain both their data and their code. This is called _________.

3.

With static classes, public variables and routines are always available to code via the static class in other modules. Is this true with public variables and routines in classes?

4.

True or False: Each object derived from a class has its own set of module-level data.

5.

What must you do to create a property that can be read but not changed by client code?

6.

What's the best way to store the internal value of a property within a class?

7.

Which is generally superior, early binding or late binding?

8.

If an object variable is declared as object, is it early bound or late bound?

9.

What's the best way to destroy an object reference?

Answers

1.

Class

2.

Encapsulation

3.

No, an object would first have to be instantiated before the variables and methods would be available.

4.

True

5.

Omit the set construct in the property procedure.

6.

Store the internal value in a private class-level variable.

7.

Early binding is almost always superior to late binding.

8.

The object is late bound.

9.

Set the object variable equal to null.

Exercises

1.

Add a new property to your class called DropsInABucket. Make this property a long, and set it up so that client code can read the property value but not set it. Finally, add a button to the form that, when clicked, prints the value of the property to the Output window. When this is working, modify the code so that the property always returns 1,000,000.

2.

Add a button to your form that creates two object variables of type clsMyClass(). Use the new keyword to instantiate a new instance of the class in one of the variables. Then set the second variable to reference the same object and print the contents of the Height property to the Output window.




Sams Teach Yourself Microsoft Visual C# 2005 in 24 Hours, Complete Starter Kit
Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
ISBN: 0672327406
EAN: 2147483647
Year: N/A
Pages: 248
Authors: James Foxall

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net