代码:

 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. Python之路:Python 基础(二)

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'lenliu' print name 下面的结论对吗?(对) 外层变量,可以被 ...

  2. poj 1150 The Last Non-zero Digit

    /** 大意: 求A(n,m)的结果中从左到右第一个非零数 思路: 0是由2*5的得到的,所以将n!中的2,5约掉可得(2的数目比5多,最后再考虑进去即可) 那n!中2 的个数怎么求呢? int ge ...

  3. poj 1850/poj 1496

    http://poj.org/problem?id=1850 -----------------http://poj.org/problem?id=1496 两题解法类似..本题为组合数学的题,要求所 ...

  4. paip.php-gtk 桌面程序 helloworld总结

    paip.php-gtk 桌面程序 helloworld总结 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.cs ...

  5. android 项目中使用到的网络请求框架以及怎样配置好接口URL

    我们在做项目中一定少不了网络请求,如今非常多公司的网络请求这块好多都是使用一些比較好的开源框架,我项目中使用的是volley,如今讲讲一些volley主要的使用,假设想要具体的了解就要去看它的源代码了 ...

  6. Android FragmentPagerAdapter和FragmentStatePagerAdapter的区别

    FragmentPagerAdapter官方解释: This version of the pager is best for use when there are a handful of typi ...

  7. iOS开发中两个不错的宏定义

    /** Synthsize a weak or strong reference. Example: @weakify(self) [self doSomething^{ @strongify(sel ...

  8. error C2664: “LoadLibraryW”: 不能将参数 1 从“const char *”转换为“LPCWSTR”

    在使用VS2010编写运行时动态链接dll文件时出现的一个问题,问题解决得益于此文章: http://blog.sina.com.cn/s/blog_6a2236590100xbgl.html 通过调 ...

  9. javascript 入门之简单换肤效果

    大家好,我是小强老师,这里简单入门 做一个换肤效果 效果如图所示: 这个案例思路分为两部分: 获取元素对象. var pic1 = document.getElementById('pic1'); v ...

  10. 【HTTP 2】HTTP/2 协议概述(HTTP/2 Protocol Overview)

    前情提要 在上一篇文章<[HTTP 2.0] 简介(Introduction)>中,我们简单介绍了 HTTP 2. 在本篇文章中,我们将会了解到 HTTP 2 协议概述部分的内容. HTT ...