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变量?这两个问题困扰过我一段时间,查了一些网上的答案,大多从“闭包”概念入手,理解起来 ...
随机推荐
- Softmax回归(使用tensorflow)
# coding:utf8 import numpy as np import cPickle import os import tensorflow as tf class SoftMax: def ...
- JavaScript的事件绑定及深入
事件绑定分为两种:一种是传统事件绑定(内联模型,脚本模型),一种是现代事件绑定 (DOM2 级模型).现代事件绑定在传统绑定上提供了更强大更方便的功能. 一.传统事件绑定的问题传统事件绑定有内联模型 ...
- 通过JavaScript更新UpdatePanel备忘
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs ...
- linux终端-console
echo $TERM 在ssh上是xterm 在console上是linux setterm -foreground black -background white -store http://blo ...
- unity, OnTriggerStay/OnTriggerStay2D not called every fixedUpdate frame
ref: http://answers.unity3d.com/questions/1268607/ontriggerstay2d-do-not-called-every-fixedupdate-un ...
- 【转】关于B/S架构应用程序的权限设置分析和总结
来自:http://www.cnblogs.com/zhouxunyu/p/3790122.html 分析:不同的用户登录到系统后赋予不同的操作权限,而用户存在于数据库中,标识用户权限的字段也保存在数 ...
- 运用cookie登陆人人网爬取数据
浏览器访问WEB服务器的过程 在用户访问网页时,不论是通过URL输入域名或IP,还是点击链接,浏览器向WEB服务器发出了一个HTTP请求(Http Request),WEB服务器接收到客户端浏览器的请 ...
- MySQL Show命令的使用
show tables或show tables from database_name; 解释:显示当前数据库中所有表的名称 show databases; 解释:显示mysql中所有数据库的名称 sh ...
- Redis 实现高效不遗漏的事件封装
虽然Redis有订阅功能,但是订阅功能是实时的,过了这个点,就接收不到消息了. 同时,如果订阅的客户端因为某些特殊原因shutdown了,那也就找不回未处理完整的订阅事件了. 但好在,Redis还有一 ...
- oracle11g服务项及其启动顺序
oracle安装完成后共七个服务,含义分别为: 1. Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Ser ...