zoukankan      html  css  js  c++  java
  • 内部类对象的获取!《Thinking in Java》随笔018

     1 //: Parcel1.java
     2 // 研究内部类(inner class)
     3 
     4 package cn.skyfffire;
     5 
     6 public class Parcel1 {
     7     /* 第一个InnerClass */
     8     static class Contents {
     9         private int i = 11;
    10         
    11         public int value() {
    12             return i;
    13         }
    14     }
    15     /* 第二个InnerClass */
    16     static class Destination {
    17         private String label;
    18         
    19         Destination(String whereTo) {
    20             label = whereTo;
    21         }
    22         
    23         String readLabel() {
    24             return label;
    25         }
    26     }
    27     
    28     /* 两个内部类获取器 */
    29     static Contents makeContents() {
    30         return new Contents();
    31     }
    32     
    33     static Destination makeDestination(String str) {
    34         return new Destination(str);
    35     }
    36 
    37     public static void main(String[] args) {
    38         Parcel1.Destination d = Parcel1.makeDestination("hahaha");
    39         Parcel1.Contents c = Parcel1.makeContents();
    40         
    41         System.out.println(c.value());
    42         System.out.println(d.readLabel());
    43     }
    44 }
  • 相关阅读:
    压缩与解压缩
    权限和特殊权限
    用户和组
    bash基础特性
    vim编辑器
    目录及文件操作命令
    ye
    软件包的安装与管理
    磁盘管理
    归档与展开归档
  • 原文地址:https://www.cnblogs.com/skyfffire/p/6491188.html
Copyright © 2011-2022 走看看