Java this 返回当前对象
2008-05-26 16:33
225 查看
this表示当前对象:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public class Construct ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private int i = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
Construct incrument()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
void printf()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
public static void main(String[] args) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Construct c = new Construct();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
c.incrument().incrument().incrument().printf();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
results: 3
相关文章推荐
- java继承:属性不具有多态性 和 return this 返回当前对象
- 面向对象编程,C#,Java中都有this,this代表了当前的对象,那么JavaScript中this代表什么
- Java读取数据库Blob对象返回到JSP页面和getOutputStream() has already been called for this response异常处理
- Java this 关键字返回当前类实例变量
- Java返回当前对象的好处
- 2.2.6对象锁synchronized(this)锁定的是当前对象
- 变量可见性和volatile, this逃逸, 不可变对象, 以及安全公开--Java Concurrency In Practice C03读书笔记
- java/构造函数,函数的重载,this的运用,构造函数的重载,静态函数,静态初始化,import,对象的继承,
- Java常用类:Data()的用法,获得当前日期和时间对象date 定义对象Date date1 = new Date(36000000);获得包含的日期和时间 比较date和date1是否相等
- Java(九)——Java对象的this引用
- this关键字的作用 使用this调用其他构造方法 使用this表示当前对象
- 黑马程序员--java面向对象之this的作用总结
- JavaScript中远程级联调用(RPC)java对象中的方法并返回结果
- Java 多线程 (PART XII)synchronized(V) 非this 对象X和String常量池
- java 中 this 类名 对象名 的作用
- java类和对象之this关键字
- JQuery获取this当前对象子元素对象
- 第十八、Java面向对象之this
- Java中This ,Static,对象,对象的引用 等关键字的理解
- StaticCodeDemo.java:29: 错误: 方法声明无效; 需要返回类型 person(){//给对应的对象进行针对性的初始化。