this指针
来源:互联网 发布:愚人节整蛊软件 编辑:程序博客网 时间:2024/06/05 17:41
this 指向的是自己 翻译成中文 "我"
一.构造函数中
指向的是 正在初始化的对象
二.用在方法中
指向的是 正在调用该方法的对象
s1.study();//在study()中的this 指向的是s1
三.使用this可以来调用其他的构造函数
public Student(int sno,String name,int age){ this(sno,name);//调用其他的构造函数 int String 这句话必须要写到当前构造函数的第一句 否则编译报错 System.out.println("使用三个参数的构造函数int sno,String name,int age"); this.age = age;}
四、演示代码
/* this的使用方法 public Test703(int sno ,String name){ this.sno=sno; this.name=name;//构造函数中 this指向的是正在初始化该方法的对象 } public Test703(int sno,String name,int age){ this(sno,name); }*/ public void study(String name){ System.out.println("木人"+name);//方法中this的使用哟有问题/// }
阅读全文
0 0
- this指针
- this指针
- this指针
- this指针
- this指针
- this 指针
- this指针
- this指针----
- this指针
- this 指针
- This 指针
- this指针
- This指针
- this指针
- this指针
- this 指针
- this指针
- this指针
- java框架基础 静态代理和动态代理
- Log4j日志的输出使用
- [leetcode]123. Best Time to Buy and Sell Stock III(Java)
- HTML5中的两种web存储
- 分布式系统架构(二)——一致性协议
- this指针
- 实现背景颜色随着ScrollView滑动改变的ActionBar
- python list的一些特性
- 巧用郑州SEO九个小技巧 提高网站流量
- Java_基础—集合框架(练习)
- 逆置/反转单链表+查找单链表的倒数第k个节点
- 一个案例 用异步的方式获取内容和图片
- Codeforces346B Lucky Common Subsequence(KMP+dp)
- 自定义windows登录认证(微软 Credential Providers 详解一《调用原理》)