zoukankan      html  css  js  c++  java
  • 实现多个接口

    多个接口间用,号分开即可,如

    1 /*
    2 Example8_2.cs illustrates implementing multiple interfaces
    3  */
    4
    5 using System;
    6
    7
    8 // define the IDrivable interface
    9 public interface IDrivable
    10 {
    11
    12 // method declarations
    13 void Start();
    14 void Stop();
    15
    16 // property declaration
    17 bool Started
    18 {
    19 get;
    20 }
    21
    22 }
    23
    24
    25 // define the ISteerable interface
    26 public interface ISteerable
    27 {
    28
    29 // method declarations
    30 void TurnLeft();
    31 void TurnRight();
    32
    33 }
    34
    35
    36 // Car class implements the IMovable interface
    37 public class Car : IDrivable, ISteerable
    38 {
    39
    40 // declare the underlying field used by the
    41 // Started property of the IDrivable interface
    42 private bool started = false;
    43
    44 // implement the Start() method of the IDrivable interface
    45 public void Start()
    46 {
    47 Console.WriteLine("car started");
    48 started = true;
    49 }
    50
    51 // implement the Stop() methodof the IDrivable interface
    52 public void Stop()
    53 {
    54 Console.WriteLine("car stopped");
    55 started = false;
    56 }
    57
    58 // implement the Started property of the IDrivable interface
    59 public bool Started
    60 {
    61 get
    62 {
    63 return started;
    64 }
    65 }
    66
    67 // implement the TurnLeft() method of the ISteerable interface
    68 public void TurnLeft()
    69 {
    70 Console.WriteLine("car turning left");
    71 }
    72
    73 // implement the TurnRight() method of the ISteerable interface
    74 public void TurnRight()
    75 {
    76 Console.WriteLine("car turning right");
    77 }
    78
    79 }
    80
    81
    82 class Example8_2
    83 {
    84
    85 public static void Main()
    86 {
    87
    88 // create a Car object
    89 Car myCar = new Car();
    90
    91 // call myCar.Start()
    92 Console.WriteLine("Calling myCar.Start()");
    93 myCar.Start();
    94
    95 // call myCar.TurnLeft()
    96 Console.WriteLine("Calling myCar.TurnLeft()");
    97 myCar.TurnLeft();
    98
    99 }
    100
    101 }
  • 相关阅读:
    JQuery UI
    JQuery 插件
    JQuery Ajax
    varchar和Nvarchar区别
    git冲突解决
    jquery ajax 提交信息后等待返回的提示信息
    Oracle错误 ORA-12560如何解决
    putty ssh连接老断
    myeclipse操作记录
    HTML与HTML5笔记
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2037023.html
Copyright © 2011-2022 走看看