首页 > 代码库 > this关键字
this关键字
this关键字的作用:
调用类中的属性
调用类中的方法或构造方法
表示当前对象
public class Test { public static void main(String[] args) { Person p1=new Person(); } } class Person{ private String name; private char sex; public Person(){ this("张爷爷"); } public Person(String name){ this(name,‘男‘); } public Person(String name,char sex){ this.name=name; //表示当前对象属性 this.sex=sex; //表示当前对象属性 this.fight(); //调用本类中的方法 } public void fight(){ System.out.println("呔!"+this.name+"在此,谁敢跟俺一战!"); } }
this关键字
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。