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变量?这两个问题困扰过我一段时间,查了一些网上的答案,大多从“闭包”概念入手,理解起来 ...
随机推荐
- C语言 文件读取
FILE *fp = fopen("data.txt","rt");fscanf(fp,"%d", &n ); /* 把数据放到数组 ...
- PCA人脸识别
人脸数据来自http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html 实现代码和效果如下.由于图片数量有限(40*10),将原 ...
- Singleton模式
Singleton模式的特点: 保证一个类仅有一个实例,并提供一个访问它的全局访问点. 定义一个Instance操作,允许客户访问它的唯一实例.Instance是一个类操作(C++中的一个静态成员函数 ...
- php 错误 Strict Standards: PHP Strict Standards: Declaration of .... should be compatible with that of 解决办法
错误原因:这是由于 php 5.3版本后.要求继承类必须在父类之后定义.否则就会出现Strict Standards: PHP Strict Standards: Declaration of ... ...
- ubutntu apt 源
中国开源软件中心更新服务器(北京光环新网 服务器),包含其他开源镜像: deb http://mirrors.oss.org.cn/ubuntu/ vivid main restricted univ ...
- matlab批量灰色预测
没事玩了一下matlab 发现现在网上的代码都是一组数据预测 所以我就写个批量数据的预测 顺便学习下matlab ----------------------------------我是快乐的分割线- ...
- c# 鼠标在控件上拖动 移动窗体 移动窗口
#region 移动窗体 移动窗口 private Point _mousePoint; private int topA(Control cc) { if (cc == null || cc == ...
- Jaxb笔记
摘自: http://www.blogjava.net/eagle-daiq/archive/2012/01/30/369016.html 最近项目原因,研究了下jaxb.jaxb是Java api ...
- objective-c 随便记记
1.tableview滚动到某一位置 [tableViewShow setContentOffset:CGPointMake(0, 0) animated:YES]; //解决tableView分割线 ...
- js键盘事件全面控制详解【转】
js键盘事件全面控制 主要分四个部分第一部分:浏览器的按键事件第二部分:兼容浏览器第三部分:代码实现和优化第四部分:总结 第一部分:浏览器的按键事件 用js实现键盘记录,要关注浏览器的三种按键事件类型 ...