public class Person{
private String name;
private int age;
public Person(String name,int age){
this.name=name;
this.age=age;
this.print(); //调用本类方法
}
public void print(){
System.out.println("这是一个本类方法");
}
public String getInfo(){
return "姓名:"+this.name+this.age+"岁";
}
public static void main(String[]args){
Person person=new Person("张三",20);
System.out.println(person.getInfo());
}
}
Java:调用本类方法(this关键词)
最新推荐文章于 2024-08-24 23:08:02 发布