关于匿名内部类

12.   Which   statement   is   true?  
   
  A.   An   anonymous   inner   class   may   be   declared   as   final  
  B.   An   anonymous   inner   class   can   be   declared   as   private  
  C.   An   anonymous   inner   class   can   implement   multiple   interfaces  
  D.   An   anonymous   inner   class   can   access   final   variables   in   any   enclosing   scope  
  E.   Construction   of   an   instance   of   a   static   inner   class   requires   an   instance   of   the   enclosing   outer   class.  
-------------------------------------------------------------------------------------------------------------------------------------------------
13.   Given:  
   
  1.   package   foo;  
  2.      
  3.   public   class   Outer   (  
  4.         public   static   class   Inner   (  
  5.         )  
  6.   )  
   
  Which   statement   is   true?  
   
  A.   An   instance   of   the   Inner   class   can   be   constructed   with   “new   Outer.Inner   ()”  
  B.   An   instance   of   the   inner   class   cannot   be   constructed   outside   of   package   foo  
  C.   An   instance   of   the   inner   class   can   only   be   constructed   from   within   the   outer   class  
  D.   From   within   the   package   bar,   an   instance   of   the   inner   class   can   be   constructed   with   “new   inner()” 
--------------------------------------------------------------------------------------------------------------------------------------------------
这是一个static   inner   class.所以A是正确的。
--------------------------------------------------------------------------------------------------------------------------------------------------
/**  
  A.   An   instance   of   the   Inner   class   can   be   constructed   with   “new   Outer.Inner   ()”  
  B.   An   instance   of   the   inner   class   cannot   be   constructed   outside   of   package   foo  
  C.   An   instance   of   the   inner   class   can   only   be   constructed   from   within   the   outer   class  
  D.   From   within   the   package   bar,   an   instance   of   the   inner   class   can   be   constructed   with   “new   inner()”  
  */  
  package   foo;  
  public   class   Outer  
  {  
  public   static   class   Inner  
  {  
  public     void   writeSt()  
  {  
  System.out.println("Hello");  
  }  
  }  
  }  
   
  class   TryInner  
  {  
  public   TryInner()  
  {  
  new   Outer.Inner();   //-------------A   is   OK!!!!   and   C   is   wrong.  
  }  
  }  
  ***************  
  /**  
  A.   An   instance   of   the   Inner   class   can   be   constructed   with   “new   Outer.Inner   ()”  
  B.   An   instance   of   the   inner   class   cannot   be   constructed   outside   of   package   foo  
  C.   An   instance   of   the   inner   class   can   only   be   constructed   from   within   the   outer   class  
  D.   From   within   the   package   bar,   an   instance   of   the   inner   class   can   be   constructed   with   “new   inner()”  
  */  
  package   bar;  
  class   TryPack    
  {  
  public   static   void   main(String[]   args)    
  {  
  System.out.println("Hello   World!");  
  //new   Inner();   -----------This   line   is   wrong   so   D   is   wrong;  
  new   foo.Outer.Inner();   //   You   should   write   like   this.   and   B   is   wrong    
  }  
  }  
  ************************The   Answer   is   A
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值