标签:
package com.mufeng.theninthchapter; class A { interface B { void f(); } public class BImp implements B { @Override public void f() { // TODO Auto-generated method stub } } private class BImp2 implements B { @Override public void f() { // TODO Auto-generated method stub } } public interface C { void f(); } class CImp implements C { @Override public void f() { // TODO Auto-generated method stub } } private class CImp2 implements C { @Override public void f() { // TODO Auto-generated method stub } } private interface D { void f(); } private class DImp implements D { @Override public void f() { // TODO Auto-generated method stub } } public class DImp2 implements D { @Override public void f() { // TODO Auto-generated method stub } } public D getD() { return new DImp2(); } private D dRef; public void receiveD(D d) { dRef = d; dRef.f(); } } interface E { interface G { void f(); } public interface H { void f(); } void g(); // Cannot be private within an interface: // private interface I{ // void f(); // } } public class NestingInterfaces { public class BImp implements A.B { @Override public void f() { // TODO Auto-generated method stub } } class CImp implements A.C { @Override public void f() { // TODO Auto-generated method stub } } // Cannot implement a private interface except // within that interface's defining class // class DImp implements A.D { // @Override // public void f() { // // TODO Auto-generated method stub // // } // } class EImp implements E { @Override public void g() { // TODO Auto-generated method stub } } class EGImp implements E.G { @Override public void f() { // TODO Auto-generated method stub } } class EImp2 implements E { @Override public void g() { // TODO Auto-generated method stub } class EG implements E.G { @Override public void f() { // TODO Auto-generated method stub } } } public static void main(String[] args) { A a = new A(); // Can't access A.D // !A.D ad=a.getD(); // Doesn't return anything but A.D //!A.DImp2 di2 = a.getD(); //Cannot access a member of the interface //!a.getD().f(); //Only another A can do anything with getD(): A a2=new A(); a2.receiveD(a.getD()); } }
标签:
原文地址:http://blog.csdn.net/u013693649/article/details/51981078