java内部类的作用分析
- public interface Contents {
- int value();
- }
- public interface Destination {
- String readLabel();
- }
- public class Goods {
- private class Content implements Contents {
- private int i = 11;
- public int value() {
- return i;
- }
- }
- protected class GDestination implements Destination {
- private String label;
- private GDestination(String whereTo) {
- label = whereTo;
- }
- public String readLabel() {
- return label;
- }
- }
- public Destination dest(String s) {
- return new GDestination(s);
- }
- public Contents cont() {
- return new Content();
- }
- }
- class TestGoods {
- public static void main(String[] args) {
- Goods p = new Goods();
- Contents c = p.cont();
- Destination d = p.dest("Beijing");
- }
- }
- public class Goods {
- private int valueRate = 2;
- private class Content implements Contents {
- private int i = 11 * valueRate;
- public int value() {
- return i;
- }
- }
- protected class GDestination implements Destination {
- private String label;
- private GDestination(String whereTo) {
- label = whereTo;
- }
- public String readLabel() {
- return label;
- }
- }
- public Destination dest(String s) {
- return new GDestination(s);
- }
- public Contents cont() {
- return new Content();
- }
- }
- public class Goods1 {
- public Destination dest(String s) {
- class GDestination implements Destination {
- private String label;
- private GDestination(String whereTo) {
- label = whereTo;
- }
- public String readLabel() {
- return label;
- }
- }
- return new GDestination(s);
- }
- public static void main(String[] args) {
- Goods1 g = new Goods1();
- Destination d = g.dest("Beijing");
- }
- }
- public class Goods2 {
- private void internalTracking(boolean b) {
- if (b) {
- class TrackingSlip {
- private String id;
- TrackingSlip(String s) {
- id = s;
- }
- String getSlip() {
- return id;
- }
- }
- TrackingSlip ts = new TrackingSlip("slip");
- String s = ts.getSlip();
- }
- }
- public void track() {
- internalTracking(true);
- }
- public static void main(String[] args) {
- Goods2 g = new Goods2();
- g.track();
- }
- }
- public class Goods3 {
- public Contents cont() {
- return new Contents() {
- private int i = 11;
- public int value() {
- return i;
- }
- };
- }
- }
- frame.addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent e){
- System.exit(0);
- }
- });
java内部类的作用分析的更多相关文章
- 【转】java内部类的作用分析
转自:http://blog.csdn.net/ilibaba/article/details/3866537 另收另外一篇有空的时候看:http://jinguo.iteye.com/blog/71 ...
- java内部类的作用
java内部类的作用 定义: 放在一个类的内部的类我们就叫内部类. 二. 作用: 1.内部类可以很好的实现隐藏 一般的非内部类,是不允许有 private 与protected权限的,但内部类可以 2 ...
- Java 内部类的作用
1.内部类可以很好的实现隐藏 一般的非内部类,是不允许有 private 与protected权限的,但内部类可以 2.内部类拥有外围类的所有元素的访问权限 3.可是实现多重继承 4.可以避免修改接口 ...
- 【转】java内部类的作用
http://andy136566.iteye.com/blog/1061951/ 推荐一. 定义 放在一个类的内部的类我们就叫内部类. 二. 作用 1.内部类可以很好的实现隐藏 一般的非内部类,是不 ...
- java 笔记(2) —— 内部类的作用
一.内部类简介 个人觉得内部类没多少研究价值,GUI中的事件响应算是非常典型的应用了. Java内部类其实在J2EE编程中使用较少,不过在窗口应用编程中特别常见,主要用来事件的处理.其实,做非GUI编 ...
- java内部类实现多继承
class Example1 { public String name() { return "liutao"; } } class Example2 { public int a ...
- Java内部类使用场景和作用
一.Java内部类的分类 Java内部类一般包括四种:成员内部类.局部内部类.匿名内部类和静态内部类 大多数业务需求,不使用内部类都可以解决,那为什么Java还要设计内部类呢. 二.内部类的使用场景 ...
- Java Reference 源码分析
@(Java)[Reference] Java Reference 源码分析 Reference对象封装了其它对象的引用,可以和普通的对象一样操作,在一定的限制条件下,支持和垃圾收集器的交互.即可以使 ...
- 从字节码的角度看Java内部类与外部类的互相访问
Java中non-static内部类为何可以访问外部类的变量?Java中外部类又为何可以访问内部类的private变量?这两个问题困扰过我一段时间,查了一些网上的答案,大多从“闭包”概念入手,理解起来 ...
随机推荐
- ASM磁盘组空间不足--ORA-15041:DISGROUP DATA space exhausted (生产库案例)
原创作品,出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/47277715 近日 ...
- linux包之findutils之find和xargs命令
解释 [root@localhost ~]# rpm -qa|grep findfindutils-4.4.2-6.el6.x86_64 find 路径 测试 动作 三个步骤的处理过程查找一个或多个目 ...
- unity, Additive Animtion注意事项
以下摘自官方文档:(http://docs.unity3d.com/Manual/AnimationScripting.html) Additive animations allow you to o ...
- 【转】如何让DIV水平和垂直居中
来源:http://blog.163.com/www.wxs_123/blog/static/82784664201321831746921/ 我们在设计页面的时候,经常要把DIV居中显示,而且是相对 ...
- apache mesos 安装
安装方式: Mesosphere yum 操作系统:centos7 1. 安装 rpm -Uvh http://repos.mesosphere.io/el/7/noarch/RPMS/mesos ...
- 【转】第7篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:全自动注册与反射方法分析
作者: 牛A与牛C之间 时间: 2013-12-12 分类: 技术文章 | 2条评论 | 编辑文章 主页 » 技术文章 » 第7篇:Xilium CefGlue 关于 CLR Object 与 JS ...
- Storm0.9.4安装 - OPEN 开发经验库
Storm0.9.4安装 - OPEN 开发经验库 bin/zkServer.sh start /home/guym/down/kafka_2.8.0-0.8.0/config/zookeeper.p ...
- struts2.0的工作原理
struts2并不是一个陌生的web框架,它是以Webwork的设计思想为核心,吸收struts1的优点,可以说 struts2是struts1和Webwork结合的产物. struts2 的工作原理 ...
- android中的EditView控件
android中的EditView控件 EditText继承关系:View-->TextView-->EditText ,EditText是可编辑文本框 1.EditText默认情况下,光 ...
- R提高篇(三): 数据管理一
目录: 创建新变量 变量重编码 日期值 数据排序 数据集合并 数据子集 随机取样 创建新变量 算术运算函数:x%%y [求余 x mod y, 5%%2的结果为1], x%/%y [整数除法,5% ...