Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > BOOK: Beginning Visual C#
|
BOOK: Beginning Visual C#
This is the forum to discuss the Wrox book Beginning Visual C#, Revised Edition of Beginning C# for .NET v1.0 by Karli Watson, David Espinosa, Zach Greenvoss, Jacob Hammer Pedersen, Christian Nagel, Jon D. Reid, Matthew Reynolds, Morgan Skinner, Eric White; ISBN: 9780764543821
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2004, 04:12 PM
Authorized User
 
Join Date: Jul 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual C# Exercises - Chapter 08 Answers

1. Public, Private and Protected

2. False, although, when resources are critical, calling a destructor is more timely

3. No, static properties, fields and methods may be independent of object instances

4.
Code:
                   |---------------|
                   |  HotDrink     |
                   |---------------|
                   |  Milk         |             |---------------|
                   |  Sugar        |             | <<Interface>> |
                   |---------------|             |    ICup       |
                   |  Drink()      |             |---------------|
                   |  AddMilk()    |             |  Color        |
                   |  AddSugar()   |             |  Volume       |
                   |---------------|             |---------------|
                           ^                     |  Refill()     |
                           |                     |  Wash()       |
                           |                     |---------------|
           |-----------------------------|
           |                             |
           |                             |
   |---------------|           |---------------|
   |  CupOfCoffee  |---() ICup |  CupOfTea     |---() ICup
   |---------------|           |---------------|
   |  BeanType     |           |  LeafType     |
   |---------------|           |---------------|
   |               |           |               |
   |---------------|           |---------------|
5. private void slakeThirst(object beverage)
        {
            // Employ interface polymorphism
            ICup glassWare;
            glassWare = beverage;
            glassWare.AddMilk();
            glassWare.Drink();
            glassWare.Wash();
        }
 
Old June 20th, 2007, 08:01 PM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think this code works:

I think you need to add an explicit cast to beverage.
So use:

glassware = (Icup) beverage





Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Visual C# Exercises - Chapter 08 seblake C# 2 July 26th, 2004 07:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.