---
title: "多个interface有完全相同的签名方法得情况,C#比Java得处理似乎更合理一点"
author: "liusu"
date: "2009-06-11T11:15:41Z"
tags: []
categories: ["非技术"]
slug: "interface-c-java"
draft: false
lastmod: "2009-06-11T11:15:41Z"
id: 406530
url: "https://liusu.iteye.com/blog/406530"
---

Interface A:


```java

package snippet;

public interface IAPaint {
	public void paint();
}

```


Interface B:

```java

package snippet;

public interface IBPaint {
	public void paint();
}


```


这样实现就可以了：

```java

package snippet;

public class ABImpl implements IAPaint, IBPaint {

	public void paint() {
		System.out.println("Paint");
	}

	public static void main(String[] args) {
		IAPaint implA = new ABImpl();
		implA.paint();

		IBPaint implB = new ABImpl();
		implB.paint();
	}
}


```


实现了以后，A和B接口实现共享同个方法体。

呵呵，c#可以这样：


```c#

public class SampleClass : IControl, ISurface
{
    void IControl.Paint()
    {
        System.Console.WriteLine("IControl.Paint");
    }
    void ISurface.Paint()
    {
        System.Console.WriteLine("ISurface.Paint");
    }
}


```