this关键字

只谈情不闲聊 提交于 2019-12-15 22:38:20
package com.review;/*当方法的局部变量和另类的成员变量重复的时候根据就近原则优先使用成员变量如果需要访问本类中的成员变量,需要使用格式this.成员变量名一定 在方法中使用 通过谁调用谁就是this. */public class thisPerson {    String name;    public void sayhello(String name){        System.out.println(name+"我是"+this.name);        System.out.println(this);//com.review.thisPerson@154617c this和Person地址值一样证明了通过谁调用谁就是this    }    public static void main(String[] args) {        thisPerson Person = new thisPerson();        Person.sayhello("王小尹");//王小尹我是null        System.out.println(Person);//com.review.thisPerson@154617c    }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!