java this关键字的使用
/*** this关键字的使用*/
public class Student {//成员变量private int sno; //学号private String name; //姓名private String sex; //性别private double score; //分数//构造方法public Student(){}public Student(int sno,String name,String sex){this.sno = sno;this.name = name;this.sex = sex;}public Student(int sno,String name,String sex,double score){this(sno,name,sex);this.score = score;}//成员方法public void study(){this.shout();shout();System.out.println("代码之路任重而道远!");}public void shout(){System.out.println("好好学习,天天向上!");}public void show(){System.out.println(sno+"\t"+this.name+"\t"+sex+"\t"+this.score);}public static void main(String[] args) {Student stu = new Student(7,"田七","男",100);stu.study();stu.shout();stu.show();Student stu2 = new Student();}
}
执行代码如下: