this隐式参数_内存分析

  • this关键字
    1.普通方法中,this总是指向调用该方法的对象。
    2.构造方法中,this总是指向正要初始化的对象。
    3.this不能用于static方法。
package testThis;

public class Student {
    //静态的数据
     String name;
     int id;

     public Student(String name, int id){
         this(); //通过this调用其他构造方法,必须位于第一句;
         this.name  = name;
         this.id = id;
     }

     public Student() {
         System.out.println("构造一个对象");
     }

     public void setName(String name) {
         this.name = name;
     }
    //动态的行为
    public void study() {  //默认传的隐式参数this
        this.name  = "张三";
        System.out.println(name+ "在学习");
    }   

    public void sayHello(String sname) {
        System.out.println(name+ "向" + sname + "说:同志你辛苦了!");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值