标签:方法 对象 初始 print his 使用 stat div ack
普通方法中,this总是指向调用该方法的对象;
构造方法中,this总是指向正要初始化的对象;
static方法不能使用this;
package mypro01; public class Teacher { String name; int id; //构造方法中,this总是指向正要初始化的对象; public Teacher(String name) { this.name = name; System.out.println(this.name+" is a teacher"); } public void setName(String name) { this.name=name; } //普通方法中,this总是指向调用该方法的对象; public void teach() { System.out.println(this.name+" is teaching"); } public static void main(String[] args) { Teacher t = new Teacher("wang");//wang is a teacher t.setName("qiao"); t.teach(); //qiao is teaching } }
标签:方法 对象 初始 print his 使用 stat div ack
原文地址:https://www.cnblogs.com/hapyygril/p/12350606.html