zoukankan      html  css  js  c++  java
  • Java内部类

    /**
     * Created by xfyou on 2016/11/3.
     * Java内部类演示
     * 内部类可完全进入不可见或不可用状态——对任何人都将如此。所以我们可以非常方便地隐藏实施细节
     */
    public class Parcel3 {
        /**
         * 私有的内部类
         */
        private class PContents extends Contents {
            private int i = 11;
    
            @Override
            public int value() {
                return i;
            }
        }
    
        /**
         * 受保护的内部类
         */
        protected class PDestination implements Destination {
            private String lable;
    
            private PDestination(String whereTo) {
                this.lable = whereTo;
            }
    
            @Override
            public String readLabel() {
                return lable;
            }
        }
    
        public Destination dest(String s) {
            return new PDestination(s);
        }
    
        public Contents cont() {
            return new PContents();
        }
    }
    
    abstract class Contents {
        abstract public int value();
    }
    
    interface Destination {
        String readLabel();
    }
    
    
    class Test {
        public static void main(String[] args) {
            Parcel3 p = new Parcel3();
            Contents c = p.cont();
            Destination d = p.dest("Tanzania");
            // Illegal -- can't access private class:
            //! Parcel3.PContents c = p.new PContents();
        }
    }
  • 相关阅读:
    HTML和CSS 基本要点必看
    CSS
    六个选择器
    HTML初级课程 (自学可懂)
    this
    1.作用域链
    js if 语句
    js数据类型
    ifelse语句
    三元运算符
  • 原文地址:https://www.cnblogs.com/frankyou/p/6026821.html
Copyright © 2011-2022 走看看