本帖最后由 jiangh33 于 2014-08-03 18:31:48 编辑

解决方案 »

  1.   

    private定义的类或接口不能直接new
      

  2.   

    当一个内部类使用了private修饰后,只能在该类的外部类内部使用。 
      

  3.   

    与其它属性是一样的,private修饰的类在外部不能访问,只能被该类访问。
    所以你在Test这个类去访问 A.B b = a.getB();会出错
      

  4.   

    private 类,我第一反应就是单例,写单例的时候会用,其他的时候我没怎么用过。
    private interface 木有见过。
      

  5.   

    而且我记得interface只能public 和default吧
      

  6.   

    私有类一般是内部类,不允许在外部创建该类对象public class Test { public static void main(String [] args){
    new demo().new A();//true
    new demo().new B(); //false
    }
    }class demo {
    public class A {
    // do something
    } private class B {
    // do something
    }
    }
      

  7.   

    首先,我刚学java,我理解的类是public或者默认的:
    public类可以被其他包使用,而默认的只能在自己包里使用。其次,好像有private类,是实现内部类的,具体还没学到。
      

  8.   

    内部类也是类成员,设置为private就不能被外部访问.
      

  9.   

    你既然 知道   ”private的属性或方法含义明确,即不能在类外部引用“  为什么还  A.B   呢??  所以这个与你说的自相矛盾  ,既然B被private  修饰   所以A.B 编译报错
      

  10.   

    package est.net;
    public class Test5 {    public static void main(String[] args) {
                A a = new A();
                 A.B b = a.getB();
                a.getB().f();
                 a.receiveB(a.getB());
                 A.B b=a.new BImpl();
                A.BImpl bImpl =  a.new BImpl();
               bImpl.f();
                print("" + (a.getB() instanceof A.BImpl));
       }    private static void print(String msg) {
                System.out.println(msg);
        }
    }class A {
        private interface B {
                void f();
        }    public class BImpl implements B {
                public void f() {
                 System.out.println("hello");
                }
        }    public B getB() {
                return new BImpl();
        }    public void receiveB(B b) {
         b.f();
        }
    }
    B是私有的不能再类外引用;
      

  11.   

    private类的含义是使类拥有一个类成员变量,which能拥有类的一些feature。
    我想了个使用情况,工作中我从没这样使用过,但我觉得这样写还可以,你只看看就可以了。public class A{
            private interface I{void dosth();}
            private class B implements I{public void dosth(){}}
            private class C implements I{public void dosth(){}}
            private class D implements I{public void dosth(){}}
            public static void outwardInterface(int type){
                    I i = null;
                    switch(type){
                            case 0:i = new A(). new B();
                            case 1:i = new A(). new C();
                            case 2:i=new A(). new D();
                            default:i=new A(). new B();
                    }
                   i.dosth();
            }
    }