Java之嵌套接口

在学习接口的过程中,这次的嵌套接口对接口的知识覆盖的更加全面,所以在这为读者们进行讲解。

嵌套接口

**:指接口可以嵌套在类或其他的接口中。但凡事的存在必有其必然性,也存在一定的规则约束。接下来我们通过以下代码进行分析得出我们应该掌握的一些规则。

package lession08;
class A{
	interface B{
		void f();
	}
	public class BImp implements B{
		public void f() {}
	}
	private class BImp2 implements B{
		public void f() {}
	}
	public interface C{
		void f();
	}
	class CImp implements C{
		public void f() {}
	}
	private class CImp2 implements C {
		public void f() {}
	}
	private interface D{
		void f();
	}
	private class DImp implements D{
		public void f() {}
	}
	public class DImp2 implements D{
		public void f() {}
	}
	public D getD() {
		return new DImp2();
	}
	private D dRef;
	public void receiveD(D d) {
		dRef=d;
		dRef.f();
	}	
}
interface E{
	interface G{
		void f();
	}
	//Redundant "public"
	public interface H{
		void f();
	}
	void g();
	//can't be private within an interface:
	//!private interface
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值