using System;
using System.Collections.Generic;
using System.Text;

namespace MyTester
{
    public interface IStorable {
        void Read();
        void Write();
    }

public class Document:IStorable
    {
        public Document(String s) {
            Console.WriteLine("Createing Document with:{0}",s);       
        }

//实现接口类的Read方法并声明为虚方法,可以被子类重写
        public virtual void Read()
        {
            Console.WriteLine("Document Read Method for IStorable");
        }

//实现接口类的Write方法
        public void Write()
        {
            Console.WriteLine("Document Write Method for IStorable");
        }
    }

public class Note : Document {
        public Note(String s):base(s) {
            Console.WriteLine("Creating note with:{0}",s);
        }

//重写Document类的Read方法
        public override void Read()
        {
            Console.WriteLine("Overriding the Read method for Note");
        }

//Note重新创建的Write方法,只属于Note本身
        public new void Write() {
            Console.WriteLine("Implementing the Write method for Note!");
        }
    }

public class Tester {
        static void Main() {
            Document theNote = new Note("Test Note");
            IStorable isNote = theNote as IStorable;
            if (isNote != null) {
                isNote.Read();
                isNote.Write();
            }
            
            Console.WriteLine("\r\n");

theNote.Read();
            theNote.Write();

Console.WriteLine("\r\n");

Note note2 = new Note("Second Test");
            IStorable isNote2 = note2 as IStorable;
            if(isNote != null){
                isNote2.Read();
                isNote2.Write();
            }

Console.WriteLine("\r\n");

note2.Read();
            note2.Write();

Console.ReadLine();
        }
    }
}

C# - 重定义一个接口的实现的更多相关文章

  1. Java 基础 面向对象: 接口(interface )概念 以及接口之练习3 -定义一个接口用来实现两个对象的比较并 判断instanceof是否为同类

    接口(interface )概念概念笔记 及测试代码: /** 面向对象: 接口(interface ) 是与类并行的一个概念: * 1.接口可以看成一个特殊的抽象类,它是常量与抽象方法的一个集合 * ...

  2. 定义一个接口CanFly,描述会飞的方法public void fly();

    1.使用类与接口的知识完成如下要求:(1)定义一个接口CanFly,描述会飞的方法public void fly();(2)分别定义类飞机和鸟,实现CanFly接口.(3)定义一个测试类,测试飞机和鸟 ...

  3. C++:如何正确的定义一个接口类

    C++中如何定义接口类?首先给接口类下了定义:接口类应该是只提供方法声明,而自身不提供方法定义的抽象类.接口类自身不能实例化,接口类的方法定义/实现只能由接口类的子类来完成. 而对于C++,其接口类一 ...

  4. 如何定义一个接口(接口Interface只在COM组件中定义了,MFC和C++都没有接口的概念)

    接口是COM中的关键词,在c++中并没有这个概念.接口是一种极度的抽象.接口用在COM组件中有自己的GUID值,因此定义接口时一定要指定它的GUID值. 实际上接口就是struct,即#define ...

  5. 38.利用接口做参数,写个计算器,能完成+-*/运算 (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) 此方法要求能够:1.用传递过来的对象调用comp

    //接口Compute package jieKou; public interface Compute { int Computer(int n,int m); } //加 package jieK ...

  6. (1)定义一个接口CanFly,描述会飞的方法public void fly(); (2)分别定义类飞机和鸟,实现CanFly接口。 (3)定义一个测试类,测试飞机和鸟,在main方法中创建飞机对象和鸟对象, 再定义一个makeFly()方法,其中让会飞的事物飞。并在main方法中调用该方法, 让飞机和鸟起飞。

    package b; public interface CanFly { public void fly(); } package b; public class FeiJi implements C ...

  7. (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) (4)设计一个测试类

    package b; public interface Computer { int computer(int n,int m); } package b; public class Jia impl ...

  8. 利用接口做参数,写个计算器,能完成+-*/运算 (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) 此方法要求能够:1.用传递过来的对象调用compute

    package com.homework5; public interface Compute { //声明抽象方法 int computer(int n,int m); } package com. ...

  9. 重学 Java 设计模式:实战代理模式「模拟mybatis-spring中定义DAO接口,使用代理类方式操作数据库原理实现场景」

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 难以跨越的瓶颈期,把你拿捏滴死死的! 编程开发学习过程中遇到的瓶颈期,往往是由于看不 ...

随机推荐

  1. mode(思维,注意内存)

    mode Time Limit:1000MS     Memory Limit:1024KB     64bit IO Format:%lld & %llu Submit Status Pra ...

  2. 依赖注入及AOP简述(九)——单例和无状态Scope .

    三.依赖注入对象的Scope及其生命周期 在前面的章节我们讲到,依赖注入容器之所以能够区别于以往的ServiceLocator等容器,是在于其不但能够自动构建多层次的.完整的依赖关系图,并且可以管理依 ...

  3. 性能强悍的开源关系数据库PostgreSQL

    性能强悍的开源关系数据库PostgreSQL

  4. Oracle存储过程 使用游标、数组的配合查询

    查询输入的门牌号码是否在标准门牌库中存在.存在则返回相应的号码. public string GetValidate(){ OracleConnection conn = ConnectOra(); ...

  5. Hadoop 安装大纲

    安装centos,配置stable ip address,文件系统,根目录用户密码,hostname,安装相关工具 打开centos,创建hadoop用户,密码.配置eth0,onboot=YES, ...

  6. 学习Oracle一个星期以来的总结

    公司开发部门主要分2部分:.net开发和Oracle PL\SQL开发.刚入职的我被分到Oracle PL\SQL组了.Oracle是比SQL Server更大的数据库应用,我在学校只接触过SQL S ...

  7. mvc的视图中显示DataTable的方法

    mvc的视图中显示DataTable的方法: 不断的循环画出table @{ ViewBag.Title = "ShowDataTable"; } @using System.Da ...

  8. 实现一个对象验证库系列 -- 3) Fluent以及扩展方法实现 (请大神批评)

    前情回顾: 上一篇 2) 验证器实现 简单描述了下验证器的简单实现 本文将说说Fluent方式的实现,欢迎大神们指点指点 3) Fluent以及扩展方法实现 我们按照之前 Fluent 的设想以及我们 ...

  9. [Linked List]Delete Node in a Linked List

    otal Accepted: 48115 Total Submissions: 109291 Difficulty: Easy Write a function to delete a node (e ...

  10. Linux下 静态链接库 和 动态链接库

    先来说说C/C++编译过程 编译: 检查语句符号定义,将C/C++代码翻译生成中间语言. 链接: 将中间代码整合,生成可执行的二进制代码. 简单的说,库文件都是一种特殊的中间语言文件,静态库还是一种特 ...