标题:Java 内部类的实例化
取消只看楼主
liruibiao99
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-9-13
 问题点数:0 回复次数:0 
Java 内部类的实例化
public class Parcel4 {
      private class PContents{
          private int i = 11;
          public int value() { return i; }
      }
      public PContents contents() {
          PContents contents=  new PContents();
          return contents;  
      }  
      public static void main(String[] args) {
          Parcel4 parcel4=new Parcel4();
          PContents contents=parcel4.new PContents();
      }
}
为什么在 contents()方法里面PContents可以直接new出来(PContents contents=  new PContents();),
而在Main()方法里面却要创建外围类的对象,再通过外围类的对象进行new出来
Parcel4 parcel4=new Parcel4();
PContents contents=parcel4.new PContents();
搜索更多相关主题的帖子: contents private public return Java 
2014-09-15 22:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-436128-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.251243 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved