代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 接口
{
/// <summary>
/// 接口:定义一个统一的标准
/// 声明接口,接口中,只包含成员的生命,不包含任何的代码实现。
/// 接口成员总是公有的,不添加也不需要添加public,也不能声明虚方法和虚静态方法
/// </summary>
interface IBankAccount
{
//方法
void PayIn(decimal amount); //方法
bool WithShowMyself(decimal amount); //属性
decimal Balance { get; }
} /// <summary>
/// 继承自IBankAccount的接口
/// </summary>
interface ITransferBankAccount : IBankAccount
{
//转账 :转入的目的地 :转入金额
bool TransferTo(IBankAccount destination, decimal amount);
} class SaveAcount : IBankAccount
{
//私有变量
private decimal banlance; //存款
public void PayIn(decimal amount)
{
banlance += amount;
} //取款
public bool WithShowMyself(decimal amount)
{
if (banlance >= amount)
{
banlance -= amount;
return true;
}
else
{
Console.WriteLine("余额不足!");
return false;
}
} //账户余额
public decimal Balance
{
get
{
return banlance;
}
}
} //实现接口的类的相应成员必须添加public修饰
class ITransferAccount : ITransferBankAccount
{
//私有变量
private decimal banlance; //存款
public void PayIn(decimal amount)
{
banlance += amount;
} //取款
public bool WithShowMyself(decimal amount)
{
if (banlance >= amount)
{
banlance -= amount;
return true;
}
else
{
Console.WriteLine("余额不足!");
return false;
}
} //账户余额
public decimal Balance
{
get
{
return banlance;
}
} //转账
public bool TransferTo(IBankAccount destination, decimal amount)
{
bool result = WithShowMyself(amount); if (result == true)
{
destination.PayIn(amount);
} return result;
}
} class Program
{
static void Main(string[] args)
{
IBankAccount MyAccount = new SaveAcount(); ITransferAccount YourAccount = new ITransferAccount(); MyAccount.PayIn(); YourAccount.PayIn(); YourAccount.TransferTo(MyAccount, ); Console.WriteLine(MyAccount.Balance);//
Console.WriteLine();
Console.WriteLine(YourAccount.Balance);// Console.ReadKey();
}
}
}

C# - 接口的继承的更多相关文章

  1. Java学习笔记 07 接口、继承与多态

    一.类的继承 继承的好处 >>使整个程序架构具有一定的弹性,在程序中复用一些已经定义完善的类不仅可以减少软件开发周期,也可以提高软件的可维护性和可扩展性 继承的基本思想 >>基 ...

  2. 使用Json.Net处理json序列化和反序列化接口或继承类

    以前一直没有怎么关注过Newtonsoft的Json.Net这个第三方的.NET Json框架,主要是我以前在开发项目的时候大多数使用的都是.NET自带的Json序列化类JavaScriptSeria ...

  3. 线程入门之实现Runnable接口和继承Thread类

    线程的2种使用方式:实现Runnable接口和继承Thread类 1.实现Runnable接口 实现Runnable接口,必须实现run方法,也是Runnable接口中的唯一一个方法 class Ru ...

  4. C# - 接口,继承

    接口 接口是把公共实例(非静态)方法和属性组合起来,以封装特定功能的一个集合.不能像实例化一个类那样实例化接口.接口不能包含实现其成员的任何代码,而只能定义成员本身.实现过程必须在实现接口的类中完成. ...

  5. java复习(5)---接口、继承、多态

    Java作为完全面向对象语言,接口.继承和多态是三个非常重要的概念. 1.继承. (1)关键字: extends (2)子类用super()调用父类构造函数,用super().方法 调用父类的成员方法 ...

  6. java 类的继承和接口的继承

    父类 public class person { String name; int age; void eat(){ System.out.println("吃饭"); } voi ...

  7. Java进阶篇(一)——接口、继承与多态

    前几篇是Java的入门篇,主要是了解一下Java语言的相关知识,从本篇开始是Java的进阶篇,这部分内容可以帮助大家用Java开发一些小型应用程序,或者一些小游戏等等. 本篇的主题是接口.继承与多态, ...

  8. C#简单接口和继承示例详解——快速入门

    上一篇中我们说到继承,其实他们之间是差不多的. 接口是方法的抽象,如果不同的类有同样的方法,那么就应该考虑使用接口. C#中接口可以多继承,接口之间可以相互继承和多继承.一个类可以同时继承一个类和多个 ...

  9. 第五节:详细讲解Java中的接口与继承

    前言 大家好,给大家带来详细讲解Java中的接口与继承的概述,希望你们喜欢 什么是接口(interface) 接口中的方法都是抽象方法,public权限,全是抽象函数,不能生成对象 interface ...

  10. java接口可以继承多个接口

    接口是常量值和方法定义的集合.接口是一种特殊的抽象类.   java类是单继承的.classB Extends classA java接口可以多继承.Interface3 Extends Interf ...

随机推荐

  1. Web开发在线工具

    JSON: JSON格式化工具 JSON检验并格式化工具 专为Web开发者准备的 63个免费在线工具

  2. CentOS搭建PHP服务器环境(LAMP)

    安装httpd mysql mysql-server php: yum install -y httpd mysql mysql-server php php-devel 安装php的扩展 yum i ...

  3. 面向对象程序设计-C++ Finial exam review NOTES【第十六次上课笔记】

    写在前面: 我记得也不全,如果有记录的更全的同学可以留言,我会添加哒 :) 常量 内敛函数 为什么需要内敛函数 内敛函数适用于什么场合 内敛函数本身,最大优点是,避免了真正函数调用的开销 因为普通函数 ...

  4. 【转】NP-Hard和NP-Complete的区别

    原文来自:http://hi.baidu.com/nuclearspace/item/e0f8a1b777914974254b09f4 对 NP-Hard问题和NP-Complete问题的一个直观的理 ...

  5. java学习之线程池的实现

    package com.gh.threadpoor; import java.util.concurrent.ExecutorService; import java.util.concurrent. ...

  6. 11427 - Expect the Expected(概率期望)

    11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...

  7. swift优秀学习博客

    http://www.00red.com/ http://www.cnblogs.com/kenshincui/  优秀的某博客,包含大量iOS的全面的总结 https://github.com/Co ...

  8. AFNetworking3.0的基本使用方法

    前一段时间在做项目的时候发现AFNetworking3.0已经被大众所接受,所以以后肯定会有很多程序猿朋友必须了解和转移至3.0了,这是我这段时间使用和学习总结出来的一些常用的知识点,希望对大家有用. ...

  9. BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )

    因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...

  10. javascript (string 部分)

    <html> <body> <script type="text/javascript"> var str="ab:cd:ef:gh& ...