Java 基础【01】 This 用法
来源:互联网 发布:个人信用数据库 编辑:程序博客网 时间:2024/05/17 18:00
1
2
3
4
5
public
class
A{
public
A getA(){
return
this
;
//表示获取当前实例本身
}
}
1
2
3
4
5
6
public
class
A{
private
int
a =
0
;
//位置1
public
A getA(
int
a){
this
.a = a;
//前面this.a表示 位置1 的a,赋值=号右侧的表示参数a
}
}
1
2
3
4
5
6
7
public
class
A{
public
A(
int
a){
}
public
A(){
this
(
1
);
//这里调用自身的构造函数public A(int a){
}
}
public class ThisDemo { String name="Mick"; public void print(String name){ System.out.println("类中的属性 name="+this.name); System.out.println("局部传参的属性="+name); } public static void main(String[] args) { ThisDemo tt=new ThisDemo(); tt.print("Orson"); }}
public class ThisDemo { int number; ThisDemo increment(){ number++; return this; } private void print(){ System.out.println("number="+number); } public static void main(String[] args) { ThisDemo tt=new ThisDemo(); tt.increment().increment().increment().print(); }}
public class ThisDemo { String name; int age; public ThisDemo (){ this.age=21; } public ThisDemo(String name,int age){ this(); this.name="Mick"; } private void print(){ System.out.println("最终名字="+this.name); System.out.println("最终的年龄="+this.age); } public static void main(String[] args) { ThisDemo tt=new ThisDemo("",0); //随便传进去的参数 tt.print(); }}
阅读全文
0 0
- Java 基础【01】 This 用法
- Java 基础【01】 This 用法
- Java基础【01】this用法
- Java 基础【01】 This 用法
- Java 基础【01】 This 用法
- Java基础之This用法
- Java基础--static、this、super用法
- Java基础--static、this、super用法
- Java基础:this和super的用法
- Java 基础——This 用法
- Java 基础——This 用法
- Java基础巩固:static、this、super、final用法
- 黑马程序员:Java基础总结----this的用法(super)
- Java基础篇(关于this的一些用法)
- Java基础之(四) this的用法
- Java-面向对象(基础篇)--this关键字的用法
- java基础-this和super的用法总结
- Java 基础(3) —— this 的用法
- shell中参数传递
- [LeetCode] Coin Change
- 【计算机视觉】 相机姿态估计之标记检测-相机标定ArUco和ChArUco 5
- JVM垃圾回收机制与内存回收
- 对链表排序
- Java 基础【01】 This 用法
- 微信小程序 五 下拉刷新
- X79-UD5 BIOS
- mysql--explain分析
- 工程师文化见解一二
- 使用VB操作Excel(随笔记录)
- 深度学习在推荐领域的应用
- 浅谈HTTP中Get与Post的区别
- 安装JDK出现问题 Error opening registry key'software\Javasoft\Java Runtime Environment'