illustrates interface member hiding : Interface « Language Basics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Language Basics » InterfaceScreenshots 
illustrates interface member hiding
illustrates interface member hiding

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example8_8.cs illustrates interface member hiding
*/

using System;


// define the IDrivable interface
public interface IDrivable
{
  void TurnLeft();
}


// define the ISteerable interface (derived from IDrivable)
public interface ISteerable : IDrivable
{
  new void TurnLeft();  // hides TurnLeft() in IDrivable
}

// Car class implements the IMovable interface
class Car : ISteerable
{

  // explicitly implement the TurnLeft() method of the ISteerable interface
  void ISteerable.TurnLeft()
  {
    Console.WriteLine("ISteerable implementation of TurnLeft()");
  }

  // implement the TurnLeft() method of the IDrivable interface
  public void TurnLeft()
  {
    Console.WriteLine("IDrivable implementation of TurnLeft()");
  }

}


public class Example8_8
{

  public static void Main()
  {

    // create a Car object
    Car myCar = new Car();

    // call myCar.TurnLeft()
    Console.WriteLine("Calling myCar.TurnLeft()");
    myCar.TurnLeft();

    // cast myCar to ISteerable
    ISteerable mySteerable = myCar as ISteerable;
    Console.WriteLine("Calling mySteerable.TurnLeft()");
    mySteerable.TurnLeft();

    // cast myCar to IDrivable
    IDrivable myDrivable = myCar as IDrivable;
    Console.WriteLine("Calling myDrivable.TurnLeft()");
    myDrivable.TurnLeft();

  }

}

           
       
Related examples in the same category
1. Demonstrate the ByTwos interfaceDemonstrate the ByTwos interface
2. Demonstrate the ByTwos interface 2Demonstrate the ByTwos interface 2
3. Use a property in an interfaceUse a property in an interface
4. Add an indexer in an interfaceAdd an indexer in an interface
5. One interface can inherit anotherOne interface can inherit another
6. Explicitly implement an interface memberExplicitly implement an interface member
7. Use explicit implementation to remove ambiguityUse explicit implementation to remove ambiguity
8. Two class inherit one interfaceTwo class inherit one interface
9. Using interface 3Using interface 3
10. illustrates interfacesillustrates interfaces
11. illustrates implementing multiple interfacesillustrates implementing multiple interfaces
12. illustrates inheriting from a class and implementing multiple interfacesillustrates inheriting from a class and implementing multiple interfaces
13. illustrates casting an object to an interfaceillustrates casting an object to an interface
14. illustrates deriving an interface from one interfaceillustrates deriving an interface from one interface
15. illustrates deriving an interface from multiple interfacesillustrates deriving an interface from multiple interfaces
16. illustrates an explicit interface member implementationillustrates an explicit interface member implementation
17. Demonstrates the use of a simple interfaceDemonstrates the use of a simple interface
18. Interface demoInterface demo
19. Interface demo: implements two interfacesInterface demo: implements two interfaces
20. Interface castingInterface casting
21. Overriding InterfacesOverriding Interfaces
22. Overriding Interfaces: Tester Overriding InterfacesAsOverriding Interfaces: Tester Overriding InterfacesAs
23. A safe method of determining whether a class implements a particular interfaceA safe method of determining whether a class implements a particular interface
24. Interfaces:Working with InterfacesInterfaces:Working with Interfaces
w__w_w___.___j_av_a_2__s__.__c_om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.